在“统一2020.3.25 3d模式”中,我有一位名为“士兵”的动画大师,当你按箭头键或某些字母键时,他应该从Idle到Walk过渡。在编辑然后项目设置的默认水平是左箭头或字母A旋转左,或旋转右箭头或字母D垂直移动是向上和向下箭头或字母S向下移动或字母W向上移动。可以看到,所有的连接都与其相应的字段有关。下面是附加到字符的C#代码。而不是角色从伊德尔过渡到步行,当你按下键,整个场景移动。以下是C#代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankControls : MonoBehaviour
{
public GameObject thePlayer;
public bool isMoving;
public float horizontalMove;
public float verticalMove;
void Update ()
{
if (Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
{
isMoving = true;
thePlayer.GetComponent<Animator>().Play("Walk");
horizontalMove = Input.GetAxis("Horizontal") * Time.deltaTime * 150;
verticalMove = Input.GetAxis("Vertical") * Time.deltaTime * 3.9f;
thePlayer.transform.Rotate(0, horizontalMove, 0);
thePlayer.transform.Translate(0, 0, verticalMove);
}
else
{
isMoving = false;
thePlayer.GetComponent<Animator>().Play("Idle");
}
}
}
发布于 2021-12-24 14:30:21
ThePlayer
公共字段在编辑器中可见。您可以检查那里引用的是哪个GameObject
,我怀疑它是一个带有Camera
组件的Transform
。您可以只转换或旋转转换(不需要thePlayer
)。Infront
)。更好的做法是兑现TankControls
Monobehaviour
在Awake
调用中附加的转换。或者,只需检查哪个GameObject
附加到thePlayer
字段。
https://stackoverflow.com/questions/70476694
复制相似问题