Hey guys, sorry to bother.
I have two gameobject in my game, one with a trigger, one with a render. I’d like the trigger to activate the render when something is touching it, but to deactivate it when it’s not.
I thought I had it nailed with this
using UnityEngine;
using System.Collections;
public class warning1 : MonoBehaviour {
public GameObject myrender;
void OnTriggerStay () {
Debug.Log ("Warning!");
myrender.SetActive (true);
}
void OnTriggerExit () {
myrender.SetActive (false);
}
}
But it doesn’t work. When something enter the collider it does turn on the render object, but it doesn’t turn it off when the collider is empty again…
EDIT: I’m trying to set up a warning system against my enemy with this in fact.
So I put on my enemies an empty object with a collider and set it so the trigger can only be touched by those. That way, when my enemies reach the trigger, the render should go on and alert my players, and once he destroy them, the render should go off.
The log tell me my enemies entering the trigger is detected, but when the enemies are destroyed (and their triggering collider with them) the render don’t go off.
However if I move the trigger on top of my enemies, then away again, the render does go on and off as I want.
It seems as if the trigger doesn’t detect my enenmies destruction as a way of leaving the trigger.