看unity中如何简单的控制人物脚步Unity3D中Animation的常见属性及方法
【AppleScript】 
function Play (mode : PlayMode = PlayMode.StopSameLayer) : bool
function Play (animation : string, mode : PlayMode = PlayMode.StopSameLayer) : bool
      Play()将开始播放名称为animation的动画,或者播放默认动画。动画会突然开始播放而没有任何混合。如果模式是PlayMode.StopSameLayer,那么所有在同一个层的动画将停止播放。如果模式是PlayMode.StopAll,那么所有当前在播放的动画将停止播放。
      如果动画已经在播放过程中,别的动画将停止但是动画不会回退到开始位置。
       如果动画没有被设置成循环模式,它将停止并且回退到开始位置
       如果动画不能被播放(没有动画剪辑或者没有默认动画),Play()将返回false。
【AppleScript】
 // 播放默认动画
animation.Play();// Plays the walk animation - stops all other animations in the same layer
 // 播放walk动画 - 停止同一层的其他动画。
animation.Play("walk");
 // Plays the walk animation - stops all other animations
// 播放walk动画 - 停止其他动画。
animation.Play("walk", PlayMode.StopAll);
Animation.CrossFade淡入淡出
function CrossFade (animation : string, fadeLength : float = 0.3F, mode : PlayMode = PlayMode.StopSameLayer) : void
在一定时间内淡入名称为name的动画并且淡出其他动画。如果模式是PlayMode.StopSameLayer,在同一层的动画将在动画淡入的时候淡出。如果模式是PlayMode.StopAll,所有动画将在淡入的时候淡出。如果动画没有被设置成循环,它将停止并且在播放完成之后倒带至开始。
【AppleScript】 纯文本查看 复制代码
 // Fade the walk cycle in and fade all other animations in the same layer out.
// 淡入walk循环并且淡出同一层的所有其他动画。
// Complete the fade within 0.2 seconds.
// 在0.2秒之内完成淡入淡出。
animation.CrossFade("Walk", 0.2);
 // Makes a character contains a Run and Idle animation
// fade between them when the player wants to move
// 让一个角色包含Run和Idle动画,并且在玩家想移动的时候在他们之间淡入淡出。
function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("Run");
else
animation.CrossFade("Idle");
}
      这里列出的最常见的播放动画的两种方法,还有其他方法属性大家自觉的去查下API吧。下面我放出自己写的人物简单控制脚步,包括上下左右移动。j,k攻击。
RoleScriptContorl.cs
【AppleScript】 
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour
{
public static PlayerControl instance;
private AnimationClip animationClip;
private CharacterController controller;
public float runSpeed = 5;
private float moveSpeed = 3;//走路速度
private string currentState="";
private GameObject monster;
void Awake()
{
instance = this;
}
void Start ()
{
controller = GetComponent<CharacterController>();
print(transform.forward);
}
void Update ()
{
KeyboardControl();
}
void KeyboardControl()
{
Vector3 forward = transform.TransformDirection(Vector3.forward);//从自身坐标转换为世界坐标
if(Input.GetKey(KeyCode.W))
{
if(Input.GetKey(KeyCode.LeftShift))
{
currentState = RoleAnimationState.RUN;//改变人物动画状态
PlayAnimation(currentState);//播放动画
controller.SimpleMove(forward * runSpeed * Time.deltaTime*100);
}
else
{
currentState = RoleAnimationState.WALK;
PlayAnimation(currentState);
controller.SimpleMove(forward * moveSpeed * Time.deltaTime * 100);
}
}
if (Input.GetKey(KeyCode.S))
{
Vector3 back = transform.TransformDirection(Vector3.back);
currentState = RoleAnimationState.WALK;
PlayAnimation(currentState);
controller.SimpleMove(back * moveSpeed * Time.deltaTime * 100);
}
if (Input.GetKey(KeyCode.A))
{
Vector3 up = transform.TransformDirection(Vector3.up);
transform.Rotate(Vector3.up * -50 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
Vector3 up = transform.TransformDirection(Vector3.up);
transform.Rotate(Vector3.up * 50 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.J))
{
currentState = RoleAnimationState.ATTACK;
PlayAnimation(RoleAnimationState.ATTACK);
}
if (Input.GetKey(KeyCode.K))
{
currentState = RoleAnimationState.ATTACK01;
PlayAnimation(RoleAnimationState.ATTACK01);
}
if(currentState!=RoleAnimationState.IDLE && !animation.IsPlaying(currentState))
{
PlayAnimation(RoleAnimationState.IDLE);
}
}
void PlayAnimation(string name)
{
currentState = name;
animationClip = animation[name].clip;
gameObject.animation.CrossFade(animationClip.name);
}

}

      下面是动画状态的一个脚本类
【AppleScript】 
using UnityEngine;
using System.Collections;
public class RoleAnimationState : MonoBehaviour
{
public const string IDLE="Idle";
public const string WALK = "Walk";
public const string RUN = "Run";
public const string ATTACK = "Attack";
public const string ATTACK01 = "Attack01";
}

      人物模型写真和inspector的组件内容(上面的代码直接挂在模型上就可以用的了。)



       为了方便大家学习,我把人物模型共享给大家。脚本上面已经有了。就不重复了。

模型网盘链接:http://pan.baidu.com/s/1kThy8Gf