I have two objects that when they collide disable another gameobject. The problem is that I only want to have the other game object disabled while the two objects are touching and that I want to have it enabled again as soon as the two objects are no longer touching. My script is below:
using UnityEngine;
using System.Collections;
public class DestroyObject : MonoBehaviour {
public GameObject ObjectToDestroy;
public GameObject TheObject;
public GameObject Player;
void OnCollisionEnter(Collision col) {
if (col.gameObject == TheObject) {
ObjectToDestroy.SetActive (false);
}
}
}
OnCollisionExit() { if (col.gameObject == TheObject) { ObjectToDestroy.SetActive(true); } }
Why doesn't that work? \$\endgroup\$