if GUI.Button scripting problem - playing every frame!

Hi,

I am currently following some 3D Buzz tutorials on Unity basics, and I am adding simple GUI elements. The tutorial states to input the following code to make a clickable button appear and once clicked register the debug notification “hello world” in the console:

if (GUI.Button(new Rect(Screen.width / 2 -(buttonWidth/2),140,buttonWidth,buttonHeight), “Start Game”));
{

Debug.Log(“Hello World”);

}

However, when i do so, the button keeps clicking itself registering constant inputs in the debug without being clicked. Is this updating every frame, and if so, how can i stop it and make it work properly?

Many Thanks.

Colin.

The Debug.Log code isn’t part of the if statement, it’s by itself running every frame. Semi-colons end a statement, so your if statement is saying “if this button is pressed, do nothing”.

–Eric

Awesome!!! Makes perfect sense actually (3D artist not a programmer here! lol).

Many thanks for you help Eric!

I have same problem , my if(GUI.Button… button is clicking on him self dont know why here is part of function

 void ChangeCharachterMesh()
    {
        if (GUI.Button(new Rect(Screen.width / 2 - 60, Screen.height - 30, 120, 30), _charMeshName)) ;
        {
            _charachterMeshIndex++;
            InstantiateCharachterMesh();
        }
    }

Update my mistake was ; at end of GUI.Button(…)“;”