CharacterController cc;//角色控制器组件:自身会有碰撞器和刚体
float speed=2f;
void Start () {
cc = GetComponent<CharacterController>();//获取角色控制组件
}
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 pos = new Vector3(h, 0, v);//位移
//cc.SimpleMove(pos * Time.deltaTime * speed);//平面移动,自带碰撞器和重力
cc.Move(pos * Time.deltaTime * speed);//空中飞行,没有重力,自带碰撞器
}
//检验触发器
void OnTriggerEnter(Collider other)
{
print(other.gameObject.name);
}
检验碰撞器
void OnControllerColliderHit(ControllerColliderHit other)//角色控制器自带的碰撞器
{
print(other.gameObject.name + "11111111");
}