我在UNITY 3d中制作跳跃和空闲动画 . 这是代码:
使用UnityEngine;使用System.Collections;
公共课JumpingD:MonoBehaviour {
public Animator anim;
public float JumpSpeed_;
private RigidBody _Character; //rigid body of the Character
public Vector3 JumpVector;
/*The thresh Hold level for the character to jump are
1: Stay Idle
25: Jump Up
*/
void Start ()
{
anim=GetComponent<Animator>();
anim.SetFloat("JumpSpeed", 1)
}
void Update ()
{
anim.SetFloat("JumpSpeed", 1)
if(Input.GetKeyDown(KeyCode.J))
{
_Character.AddForce(JumpVector*Time.deltaTime);
anim.SetFloat("JumpSpeed", 25)
}
}
}
问题是即使按下J键后跳转动画也不会播放 . 总是空闲动画播放我想按下J键后跳转动画播放,之后字符再次空闲 .
1 回答
在每个帧调用的update方法的第一行,你将“JumpSpeed”设置为1.这意味着玩家将停止按下J键的下一帧,它会立即下降到1,所以当然是跳动画播放器按下J键后“不会播放” .