//主动方必须有Rigidbody 发生碰撞的两个游戏对象必须有Collision 被动方对于Rigidbody可有不可无
//参数是表示被动方
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);
}
//有刚体的不勾选is trigger, 被动方没有刚体,但是勾选IS Trigger
void OnTriggerEnter(Collider other)
{
//模拟子弹打到人,打到后子弹和被打目标同时消失
Debug.Log("触发器开始:" + other.gameObject.name);
GameObject.Destroy(gameObject);
Destroy(other.gameObject);
}
void OnTriggerStay(Collider other)
{
Debug.Log("触发器检测中:" + other.gameObject.name);
}
void OnTriggerExit(Collider other)
{
Debug.Log("触发器结束:" + other.gameObject.name);
}
//参数是表示被动方
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);
}
//有刚体的不勾选is trigger, 被动方没有刚体,但是勾选IS Trigger
void OnTriggerEnter(Collider other)
{
//模拟子弹打到人,打到后子弹和被打目标同时消失
Debug.Log("触发器开始:" + other.gameObject.name);
GameObject.Destroy(gameObject);
Destroy(other.gameObject);
}
void OnTriggerStay(Collider other)
{
Debug.Log("触发器检测中:" + other.gameObject.name);
}
void OnTriggerExit(Collider other)
{
Debug.Log("触发器结束:" + other.gameObject.name);
}