【问题背景】
Unity3D中开发物体的移动,实现代码如下:
public class TargetController : MonoBehaviour
{
private CharacterController character;
private float speedRate = 4f;
private void Start()
{
character = GetComponent<CharacterController>();
}
private void Update()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
Debug.Log("hor:" + hor + ", ver:" + ver);
Vector3 speed = new Vector3(hor, 0, ver) * speedRate;
character.SimpleMove(speed);
}
}
结果运行时报错信息为:
CharacterController.Move called on inactive controller
UnityEngine.CharacterController.SimpleMove (UnityEngine.Vector3)
也有其他人反馈类似问题:
https://forum.unity.com/threads/charactercontroller-move-called-on-inactive-controller.488742/
【问题原因】
请看上面截图的红色报警提示部分:Step Offset must be less or equal to <scaled Height> ...
这个提示指的是 Character对象的Step Offset设置太大了,
所以是Step Offset的原因,不用在inactive controller上寻找原因
【问题解决】
将Step Offset设置为0.1