- Home /
OnTriggerEnter does not make a GameObject active again.
Hi, I was working on just a basic script to deactivate and reactivate a GameObject. My problem is that when I enter the trigger, it works perfectly fine, deactivating the GameObject, however going through the trigger a second time does not reactivate the GameObject.
Here is what I have:
using UnityEngine;
using System.Collections;
public class Weather : MonoBehaviour {
public GameObject WeatherObject;
void OnTriggerEnter(Collider other) {
if(other.tag == "WeatherTrigger") {
if(WeatherObject.active = true) {
WeatherObject.active = false;
}
else {
WeatherObject.active = true;
}
}
}
}
If someone can help me, that would be great. Thanks.
Answer by iwaldrop · May 04, 2013 at 03:34 AM
If a GameObject is inactive then it's collider is too; you're not getting collisions. Think about turning off the WeatherObject component instead.
The weather object is just a GameObject with a particle system. That GameObject is a child of the player. I have it set so that if the player goes into the trigger tagged "WeatherTrigger", it will disable the weather object. So I'm still getting collisions, but it does not seem to work. I removed the OnTriggerEnter function and replaced it with a simple button press in Update, and it worked both activating and deactivating, so its something with OnTriggerEnter. I did, however, find a temporary solution, but it might be the only solution. Two triggers, right next to each other, one tagged "WeatherOn", the other "WeatherOff".
Your answer