using UnityEngine;
using System.Collections;
public class t2 : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider other)
{
print(" aaa " + other.gameObject.name + " " + gameObject.name);
}
void OnTriggerExit(Collider other)
{
print(" bbb " + other.gameObject.name + " " + gameObject.name);
}
void OnCollisionEnter(Collision other)
{
print(" cccc " + other.gameObject.name + " " + gameObject.name);
}
void OnCollisionExit(Collision other)
{
print(" ddd " + other.gameObject.name + " " + gameObject.name);
}
}
Cube1对象上 组件
Cube对象上组件
说明
- 不管谁进入谁,如果一个脚本执行,另一个脚本也会执行。 如cube进入cube1,如果cube上脚本触发OnTriggerEnter,cube1也会触发。
- 两个对象都要有碰撞器,但可以只有一个对象有刚体。
- is trigger勾选(只需一个勾选), is kinematic不勾选, 会同时触发triger和Collision函数
- is trigger不勾选, is kinematic勾选,不触发函数
- is trigger不勾选, is kinematic不勾选,触发Collision函数,物体同时被弹开