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.

1 Answer

1

If a GameObject is inactive then it’s collider is too; you’re not getting collisions. Think about turning off the WeatherObject component instead.