【发布时间】:2022-02-07 02:23:54
【问题描述】:
我是统一和游戏开发的初学者。我正在尝试制作一个统一的平台游戏,我想在玩家向右或向左移动时播放动画,但问题是 isMoving 变量出于某种原因是真正的动画正在播放片刻(不到一秒)然后再次变为假,并且正在播放空闲动画。
我的动画师(所有过渡都禁用退出时间):
我的运动脚本:
public class PlayerMovement : MonoBehaviour
{
private bool canPlayerJump;
private float horizontalInput;
private Animator animator;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && canPlayerJump)
{
GetComponent<Rigidbody>().AddForce(Vector3.up * 5, ForceMode.VelocityChange);
}
if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.A))
{
animator.SetBool("isMoving", true);
} else
{
animator.SetBool("isMoving", false);
}
horizontalInput = Input.GetAxis("Horizontal");
}
private void FixedUpdate()
{
GetComponent<Rigidbody>().velocity = new Vector3(horizontalInput * 5, GetComponent<Rigidbody>().velocity.y, 0);
}
private void OnCollisionEnter(Collision collision)
{
canPlayerJump = true;
Debug.Log(collision.gameObject.name);
}
private void OnCollisionExit(Collision collision)
{
canPlayerJump = false;
}
}
【问题讨论】: