how do i use gameObject.setactive with a bool?(my codes not working!)

**Basically i have a bool called switch that i’m getting from another script and i want a platform to be set as inactive when the bool is true, and active when the bool is false. i can get it to go inactive but i cant get it back to active. hope you guys can help help me out its doing my head in! i had a similar thing working with layer collisions but i think this is the better way to go :slight_smile:

here’s my code: **

using UnityEngine;
using System.Collections;

public class SwitchBlue : MonoBehaviour {

	public GameObject player;
	private ActionManager Manager;


	// Use this for initialization
	void Start () {
		Manager = player.GetComponent<ActionManager>();

	
	}
	
	// Update is called once per frame
	void Update () { 
		if (Manager.Switch == false) 
		{
			gameObject.SetActive (true);
		}

		else if (Manager.Switch == true)
		
		{
			gameObject.SetActive(false);

		} 
	   
	

}
}

thanks guys!

Once a game object is inactive then scripts on it don’t execute anymore. So this part of your script

if (Manager.Switch == false) 
{
             gameObject.SetActive (true);
}

will actually never execute since the game object will be inactive.

You can do it from another script where you get a reference to this game object and yours to set it active or inactive.

No script on game object will execute after it is inactive.

So this part of your script

if (Manager.Switch == false) 
{
             gameObject.SetActive (true);
}

will never execute since your game object is inactive.

You need to do it from an another script where you get the reference to your game object and then active or inactive it from there.

Once you disable the item the script is on, you cannot enable it again because there is no call to enable it since the item is disabled.You need the script that enables and disables the object on a different object.