1设置好人物Avatar
2创建Animator
3配置好BlendTree:事件参数组件用作动画状态机来实现播放不同的动画剪辑
4添加脚本PlayerMove.cs
5实现当按下w时,人物由站立从走到跑,放开w键时,运动停止回到站立状态
uusing UnityEngine;
using System.Collections;
public class PlayerMove : MonoBehaviour {
// Use this for initialization
public Vector3 targetPoint;
public float moveSpeed;
Animator animator;
int SpeedFloat;
void Awake () {
animator = GetComponent<Animator> ();
SpeedFloat = Animator.StringToHash("Speed");
/*
int SpeedFloate = Animator.StringToHash("Speed");
Animator animator = GetComponent<Animator> ();
animator.SetFloat (SpeedFloate, 2f);
*/
}
// Update is called once per frame
void Update () {
moveAnimation ();
}
void moveAnimation(){
/*
if (Input.GetKeyDown(KeyCode.W)) {
//id The id of the parameter. The id is generated using Animator::StringToHash.
//value The new value for the parameter.
//dampTime The time allowed to parameter to reach the value.
//deltaTime The current frame deltaTime.
animator.SetFloat(SpeedFloat,2f,0.04f,Time.deltaTime);
}
*/
if (Input.GetKey (KeyCode.W)) {
animator.SetFloat(SpeedFloat,2f,1f,Time.deltaTime);
}
if (Input.GetKeyUp (KeyCode.W)) {
animator.SetFloat(SpeedFloat,0);
}
}
}
U3D 按下“w”键使人物开始运动,放开则停止
最新推荐文章于 2023-12-29 19:17:24 发布