- Home /
OnMouseDown not firing
I've got this code, but when i press the pause button it will not execute it, if i check the Paused bool in the inspector it will execute it immediately, but how do i fix it to make it work?
#pragma strict
var paused = false;
var isButtonVisible : boolean = true;
function OnMouseDown(){
this.paused = !this.paused;
Time.timeScale = 0;
isButtonVisible = true;
}
function OnGUI(){
if ( isButtonVisible ) {
if(this.paused){
if (GUI.Button(Rect(Screen.width/2-100,Screen.height/2+3,200,50),"Restart")){
Application.LoadLevel(Application.loadedLevel);
Time.timeScale = 1;
isButtonVisible = false;
}
if (GUI.Button(Rect(Screen.width/2-100,Screen.height/2-50,200,50),"Resume")){
Time.timeScale = 1;
isButtonVisible = false;
}
// Insert the rest of the pause menu logic
if (GUI.Button(Rect(Screen.width/2-100,Screen.height/2+56,200,50),"Main Menu")){
Application.LoadLevel ("MainMenu");
isButtonVisible = false;
Time.timeScale = 1;
}
}
}
}
Answer by tanoshimi · Mar 10, 2015 at 01:17 PM
And you have a collider on this object, and it's not placed on the Ignore Raycast layer?
it is ignoring the Raycast later, it's a button that has a box collider, doesn't work
Answer by ForeignGod · Mar 10, 2015 at 01:24 PM
Make sure your object has a collider of any type on the object. OnMouseDown requires it to register you clicking the object.
a collider on the pause button? did it, still nothing happened
Your answer
Follow this Question
Related Questions
How can I change my script to un-pause my project? 1 Answer
properly handling pause functionality with javascript/unityscript? 3 Answers
Detect when user minimizes application 3 Answers
A Proper Way To Pause A Game 9 Answers
I am creating a pause button and when I click it the score keeps rising. How can I stop it? 1 Answer