Friday 18 October 2013

Button in Unity


Here's an example of a few button you'll typically see on a start menu.

Here is the code:


function OnGUI()
{
    GUI.Button(Rect(710, 175, 300, 100), "Start Game");
    GUI.Button(Rect(710, 325, 300, 100), "Options");
    GUI.Button(Rect(710, 475, 300, 100), "Quit");
}

I used java to create this code. It's simple it contains the co-ordinates to where the buttons will go on the map and the title.



Here is a working menu in Unity, as I scroll above the titles the title will turn to red.

Here is the Script:


function OnMouseEnter(){
    renderer.material.color=Color.red;
}

function OnMouseExit(){
    renderer.material.color=Color.white
}


The Start Game and Options button are working.

When I click on the Start Game you will be taken to a different scene where there's a cube on it's own.

In options you feel see a menu
that looks like this:


I have used the same code as my main menu to highlight the headings.

I have made use of the Help button and I'll be able to implement working buttons on the rest of the Headings to with ease.

This is the normal script I've used for the working buttons:

var isOptions=false;

function OnMouseEnter(){
    renderer.material.color=Color.red;
}

function OnMouseExit(){
    renderer.material.color=Color.white;
}

function OnMouseUp(){
    if (isQuit==true) {
        Application.Quit();
    }
    else {
        Application.LoadLevel(1);
    }

}

No comments:

Post a Comment