Button invokes another button

hi ,
i’m trying to create a Toggle button for play and pause.
when i press the current button it is supposed to generate a new button. but in my case it not working mean time it prints the console message.
here is my code:

var icon_play:Texture;
var icon_pause:Texture;

var play;

function OnGUI()
{
play=GUI.Button(Rect(10,Screen.height-60,50,50),GUIContent(icon_play));

if(play)
{
GUI.Button(Rect(50,Screen.height-80,50,50),GUIContent(icon_pause));
print(“button clicked”);
}

}

what is wrong with this ? can you help me?

thanks in advance. :slight_smile:

Use this code

var icon_play:Texture;
var icon_pause:Texture;

var play=false;

function OnGUI()
{

play=GUI.Toggle(Rect(10,Screen.height-60,50,50),play,GUIContent(icon_play),"button");

if(play)

    {
   GUI.Button(Rect(50,Screen.height-80,50,50),GUIContent(icon_pause));
    print("button clicked");
    }

}

another method

play=GUI.Toggle(Rect(10,Screen.height-60,50,50),play,play?GUIContent(icon_play):GUIContent(icon_pause),"button");