How to get exact button input

For some reason, when I go to click on the multiplayer buttin on the screen, it always loads this script no matter where I click on the screen. i have similar scripts on the same screen for different buttons like settings and so on. Could you help me with this script so that when I go to click on this, it loads only this and when I click on other buttons, it loads only those buttons. In other words, make the GetMouseDown part load an exact coord on the screen.

Sorry if I was not clear with my words…

#pragma strict

function Update () {
	
	if(Input.GetMouseButtonDown(0)){
 		Application.LoadLevel("LoadingCampaign");
		}
}

Hi,
You might want to consider using GUI.Button for this,

    function OnGUI() {
        GUI.Button(Rect(coordinateX, coordinateY, width, height), 
                "YourButtonText") {
            Application.LoadLevel("LoadingCampaign");
        }
    }

You can create more buttons to load the other scene that you have in the project.
Hope this helps.

Input.GetMouseButton

**static function GetMouseButton (button : int) : boolean

Description
Returns whether the given mouse button is held down.
**

As you see it is used to detect mouse input which is not what you want.

You could either use function OnMouseDown() on each button,

Or you can find the position by sending a raycast.

This has been asked a lot from before so try searching before asking :slight_smile:

Hi you can achieve the same effect using GUI Button or GUI Texture here is an script that works using GUI Button (if you want script that works with GUI Texture please do leave a comment)

var LevelName:String = "LoadingCampaign";//your Level name goes here 

function OnGUI(){//On GUI works same as Update but for GUI's
    GUI.Box(Rect(10,10,100,400),"Menu");//create a box with name Menu
    if(GUI.Button(Rect(20,70,80,20),"Start"))//create a button with name Start and if its clicked continue executing 
    {
        Application.LoadLevel(LevelName);
    }
}

You could us a raycast, or just use unity’s GUI(graphical user interface)

funtion OnGUI()
{
    if(GUI.Button(Rect(100,100,100,100),"Multiplayer"/*Or your button texture*/))
    {
        //Application.LoadLevel("LoadingCampaign");
    }
}