- Home /
donotdestroy for hud - but hud appears on main menu :(
i have a hud for a game made with guitextures and gui.buttons i added it to an empty game object and added a donotdestroy to this function so that it would carry over health, mana, skillpoints etc to the next scene
the problem im having is i have an esc menu that can bring you back to the main menu screen (to adjust options or whatever) and the hud still appears! i would like the hud to be destroyed. i tried inputing a bool variable in the esc menu to be true to destroy hud and in my hud script i had
function Awake () {
if (destroygui ==true) { Destroy (this);} // also tried Destroy ("hud"); which is name of the game object else {DontDestroyOnLoad (this);}
}
// gui code below //etc etc
any ideas ?
thanks !
Answer by Eagle32 · Aug 21, 2010 at 10:48 PM
You could add the following to your hud component.
OnLevelWasLoaded(int level)
{
if (level == ##Your menus level number##)
destroy(this);
}
would i remove what i have above and replace it with this ? or integrate this into $$anonymous$$e ?
thanks again :)
i knew what you said looked familiar - figured it out - thanks :)
function OnLevelWasLoaded(level : int) {
if (level == 1) { Destroy(this); } else { DontDestroyOnLoad (this); } }
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Access to GUI Keyboard Focus 1 Answer
Changing Font, Background/Style of GUI Buttons 1 Answer
Main menu help needed (C#) 2 Answers