void OnCollisionEnter(Collision col){Debug.Log("开始碰撞" + col.collider.gameObject.name);}void OnCollisionStay(Collision col){Debug.Log("持续碰撞中" + col.collider.gameObject.name);}void OnCollisionExit(Collision col){Debug.Log("碰撞结束" + col.collider.gameObject.name);}
发生碰撞的条件:主动方必须有Rigidbody,发生碰撞的两个游戏对象必须有Collider,被动方对于RigidBody可又不可无,参数是表示被动方
void OnTriggerEnter(Collider other){Debug.Log("触发器开始出发:" + other.gameObject.name);}void OnTriggerStay(Collider other){Debug.Log("触发器检测中:" + other.gameObject.name);}void OnTriggerExit(Collider other){Debug.Log("触发器结束:" + other.gameObject.name);}
发生触发的条件:发生碰撞的物体两者其中之一有Rigidbody即可,发生碰撞的两个游戏对象必须有Collider,其中一方勾选IsTrigger即可,参数是表示被动方