void onmouseDown missleading

Hi, im trying to do a script when something happens when you clikc unto a prefab, but it do whatever i click into it, instead when i click and the condition its “true”:

public void OnMouseDown()
    {
        if (reactive == false)
        {


            //Do stuff
               
               
        }

        }
        else
        {
            Debug.Log("Aun queda =" + countDown);
        }
    }

what can i do to fix or achive what im trying¿

You have an extra ‘}’ above the else.

1 Like

You need to fix the indenting in your script. It should look like that, after removing the extra curled bracket @Stardog mentioned:

    public void OnMouseDown()
    {
        if(reactive == false)
        {
            //Do stuff
        }
        else
        {
            Debug.Log("Aun queda =" + countDown);
        }
    }
1 Like

Well, it wasnt the problem, the problem was that i didnt copy my code right, seems, i mean, the script works perfectly, every time i need to click onto the game object, it do the things it has supouse to do, but the problem is that the thing thosent care about if the boolean value its true or not, and thats what i dont understand. Why it dosent stop when i clikc and the boleean its true

OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.”
Do you likely need to attach a collider component to the object?

1 Like

How do you know the variable is true? You really need to put a Debug.Log in the beginning of that OnMouseDown and log your variable.

1 Like

It has a collider and i alredy have it, the Debug.Log, the thing its that it just run the code inside the bollean condition even if the conditional dosent match

That is impossible. I’m pretty sure that the C# if() statements are working properly. You must set your variable wrong.
How do you set it?
And BTW, why are you doing it upside down?

if (reactive) {
[...]
} else {
[...]
}
1 Like

sorry for not answering before, i totally forgot it, yeah, csharp its fine, but i dont know, maybe i tried to make harder than it is, so i restarted all the code in order to achive trhow other way, but thanks a lot for the help