Hoping someone can help. I’m working on a network game and when instantiating a new player I want to enable/disable the HUD whether networkView.IsMine is true or not.
I have an empty Game Object called HUD. In HUD I have several additional game objects such as “CockpitFlightControlPanel”
Inside these objects I have a combination of: Transform, GUITexture and a Script. Some don’t have GUITexture, just Transform and Script.
I want to fully disable them. If in the editor under Hierarchy I choose HUD, then in the inspector I click the activate check box at the top it asks if I want to deactivate all the children. When I perform the action this way it works fine. Now I’m trying to perform the same task in code. Below is a few examples of what I’ve tried. I’ve tried just using active, just using SetActiveRecursively, both together, flipflopping the order, etc… but nothing seems to work. I’ve also tried going at just the components(script) but haven’t had much success there either. This seems like it should be a simple, easy task, but it’s driving me crazy. Any suggestions what I might be doing wrong?
When I set a breakpoint I’m hitting this part of the code, so I know that’s working. The code I’m in is part of my player spawn code which is tied to the player prefab which gets instantiated when joining a new game. The network code loads the level then instantiates the player then the player spawn code runs and attempts to tweak the level appropriately. HUD is at the root level. Its not currently part of the player, although I’ve considered moving it to the player. I was having some alignment issues, but regardless, that shouldn’t be the root cause, right?
GameObject.Find(“HUD”).active = false;
GameObject.Find(“HUD”).SetActiveRecursively= false;
GameObject.Find(“CockpitFlightControlPanel”).active = false;
GameObject.Find(“CockpitFlightInformation”).active = false;
GameObject.Find(“EnergyGuages”).active = false;
GameObject.Find(“RadarControlPanel”).active = false;
GameObject.Find(“TargetingReticle”).active = false;
GameObject.Find(“CockpitFlightControlPanel”).SetActiveRecursively(false);
GameObject.Find(“CockpitFlightInformation”).SetActiveRecursively(false);
GameObject.Find(“EnergyGuages”).SetActiveRecursively(false);
GameObject.Find(“RadarControlPanel”).SetActiveRecursively(false);
GameObject.Find(“targetingReticle”).SetActiveRecursively(false);
I’ve even tried this:
(FlightControlPanel)(GameObject.Find(“HUD”).GetComponent(typeof(FlightControlPanel),true)).enabled = false;