当我的角色在 x 轴上移动时,函数 SetFloat() 无法识别速度,但仍能识别 y 轴。我不明白为什么玩家的 sx 速度没有签署到动画师中创建的“速度”浮动
public float acceleration;
public bool isGrounded = true;
public float jumpHeight;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.Space) && isGrounded == true){
GetComponent<Rigidbody2D>().velocity = new Vector2 (0 , jumpHeight);
isGrounded = false;
}
if(GetComponent<Rigidbody2D>().velocity.y == 0){
isGrounded = true;
}
anim.SetFloat("Speed", Mathf.Abs(GetComponent<Rigidbody2D>().velocity.x));
if(Input.GetKey(KeyCode.D)){
transform.position += new Vector3 (acceleration * Time.deltaTime , 0.0f, 0.0f);
transform.localScale = new Vector3 (5,5,5);
}
if(Input.GetKey (KeyCode.A)){
transform.localScale = new Vector3 (-5,5,5);
transform.position -= new Vector3 (acceleration * Time.deltaTime , 0.0f , 0.0f);
}
}