ThirdPersonController碰撞不调用OnTriggerEnter事件
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Test : MonoBehaviour { public Transform target; // Update is called once per frame void Update () { } private void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "Test") { this.transform.position = target.position; } } }
我有一个ThirdPersonController,我希望它与立方体或圆柱体碰撞。 该脚本附加到ThirdPersonController。
我试图添加到圆柱体或立方体Rigidbody打开/关闭使用重力和Is Kinematic但没有。 它没有参加活动。
ThirdPersonController
使用CharacterController
, OnControllerColliderHit
用于不OnTriggerEnter
。
请注意,您必须使用Move
函数移动它,而不是直接通过其变换Move
它,以便调用OnControllerColliderHit
。
void OnControllerColliderHit(ControllerColliderHit hit) { }
每件事情都是正确的,但这里的错误是你正在改变与第二个物体相撞的物体的位置,但物体的东西是对撞机已经存在…..作为它的替代尝试打印任何碰撞发生时的声明
private void OnTriggerEnter(Collider other) { if (other.tag==your_tag) { print("message"); } }