How to set inactive child object to active

Hi there, I am facing an issue where I cannot activate the child object in my scene. Was wondering if there is anyway to go about this. Currently my parent object persist within scene and it is just an empty game object. The child object persist along as well but is set inactive in other scenes, however I can seem to get it to be set back to active at all. Any help is appreciated, Imgur: The magic of the Internet Attached is my persist code for reference.

void Awake () {
		if(control == null)
		{
			DontDestroyOnLoad(gameObject);
			control = this;
		}
		else if(control != this)
		{
			Destroy(gameObject);
		}
	}

1 Answer

1

Hey ultratin,

I also had a good learning experience a while ago, on how to get the object to be inactive.
I’m not sure if this helps to solve your exact problem, but here’s my example script for you:

using UnityEngine;
using System.Collections;

public class stopbubbles : MonoBehaviour {
	public GameObject Bubbles ;
	public static bool bubblesturnonoff = true;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (!bubblesturnonoff) {
		Bubbles.SetActive(false);
		}

		if (AudioListener.volume > .001f) {
			bubblesturnonoff = true;
		}
		if (AudioListener.volume <.002f){
			bubblesturnonoff = false;
		}
		else { 
			Bubbles.SetActive(true);
		}
	}
}

So, you can see that I’ve setup a variable in the beginning, actually using the gameobject as the variable, and then used the .SetActive (make sure you get those CAPS!) as true. (on Line 25) (or you can disable it with (false); )

Any further questions? Just fire 'em away or check out the Unity Manual on SetActive here: Unity - Scripting API: GameObject.SetActive

Enjoy!

Hey man, thanks a lot! but after a few hours of tinkering, I decided to parent my game object to another game object totally. That enabled me to set the children active! Thanks very much though!