- Home /
Making parent and children False in Hierarchy and opposite (true)
Hi there. Hope you can help. I've been wrestling with trying to make my platforms in the Hierarchy enabled and disabled. I have three parent objects with children objects within. On a trigger event, I want to be able to disable one object and enable the other. I've tried many things. What I have tried is this, but doesn't work. At start Level1 is active (ticked) and Level2 is not active (Un-ticked):
var Level1_Page1 : GameObject;
var Level1_Page2 : GameObject;
if(other.gameObject.tag =="Level1_Page2_Barrier"){
Level1_Page1.SetActive (false);
Level1_Page2.SetActive (true);
}
Any help and understanding would be greatly appreciated!
Rich
Are Level1_Page1 and Level1_Page2 the parent objects? How far into the code do you get?
Yes they are the parents. Inside them are the children - other objects. I've tried setting up the code like this as well:
if(other.gameObject.tag =="Level1_Page1_Barrier")
{
///Spawn Player back to start
transform.position = SpawnPoint.position;
///Save Highscore
if(chapter1Score > PlayerPrefs.GetInt("chapter1Score")){
PlayerPrefs.SetInt("chapter1Score", chapter1Score);
}
///Hide Platform objects
HideLevel1Page1();
}
function HideLevel1Page1(){
Level1_Page1.SetActive (false);
Level1_Page2.SetActive (true);
Debug.Log("End of Page1!");
}
The debug works, but the SetActive's do nothing.
Are the game objects active if you select them when playing, after the code above has run?
Answer by RichCoggin · Oct 16, 2013 at 12:00 PM
The functionality works provided the Object isn't a prefab.