- Home /
Problem using trigger to set gameobjects active
I know that this code should work and am wondering is it due to unitys update making gameObject.active = true; obsolite
var HQGood : GameObject;
var HQBad : GameObject;
function OnTriggerEnter (other : Collider) {
HQGood.SetActive(true);
HQBad.SetActive (false);
}
function OnTriggerExit (other : Collider) {
HQGood.SetActive(true);
HQBad.SetActive (false);
}
Note your OnTriggerEnter() and OnTriggerExit() are making the same active settings. Did you want to reverse them? What is not working?
Is the trigger on an inactive game object? If the game object is inactive, its triggers won't register collisions.
Thank you for that, LOL I must have been really tired to make a mistake like that. I flipped them around now they work
Great to hear! I'll post it as an answer so you can close out this question.
Answer by TonyLi · Jun 07, 2013 at 05:34 PM
The answer was to flip the objects around. The trigger was on an inactive game object. If the game object is inactive, its triggers won't register collisions.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103658im_/https://answers.unity.com/themes/thub/images/avi.jpg)