写了一个碰触的小游戏,如果“player”碰到“sad”就会消失。
void OnTriggerEnter(Collider other){ //other 传入要触碰的collider
Debug.Log("OnTrigger Enter");
if (other.gameObject.name == "sad"){
GameObject.Destory(other.gameObject); //销毁gameObject
}
}
void OnTriggerExit(){
Debug.Log("OnTriggerExit");
}
void OnTriggerStay(){
Debug.Log("OnTriggerStay")
}