Toggle button don't dissapear..

hello, this is my code

private var toggleState1 : boolean = false;

function OnGUI() {
toggleState1 = GUI.Toggle(Rect(430, 210, 100, 30), toggleState1, “Sound on/off”);
AudioListener.pause = toggleState1;
}

function Awake() {
DontDestroyOnLoad(this);
}

But if I load a new scene my button will be in all the scenes… how do I destroy the button but dont destroy if it is true?

Your problem is that you’re always doing the “DontDestroyOnLoad”, no matter what toggleState1’s value is. Notice how it’s now in an “if” statement in the code below :wink:

Hope this helps!

private var toggleState1  : boolean = false;

function OnGUI()
{
    GUI.Rect(430, 210, 100, 30); //place actual GUI rectangle code here.
}

function Awake()
{
    if(toggleState1 == true)
    {
        DontDestroyOnLoad(this);
    }
}