OnMouseDown() and enabled = false;

Hello!
There are both OnMouseDown() and Update() in my script.

If I turn the checkbox on my script in inspector (disabling it) - OnMouseDown continues to work…

So, for instance:
I create a cube, put a script on it, disable the script, click on cube and get a message from my OnMouseDown() (“cube clicked!”).

Am I doing something wrong?).

Disabling a script really only disables Update but not much else.

–Eric

Damn, I thought disabling a component is simple :smile:

Oh but it is simple! You just have a boolean called “onOff” inside the script that has to be true for anything to happen inside functions like OnMouseDown(). Then you just set enabled = false and onOff = false whenever you don’t want it doing anything.

Thanks, I am aware of OnOff :smile: .

That’s way too complicated, if you ask me. Why not just do this:

function OnMouseDown()
{
   if (enabled)
   {
      // code here
   }
}

Jim Offerman, quite a nice idea!
:slight_smile:

Only one reason, really. Sometimes you want it to respond to different stimuli but you want Update() to be turned off temporarily.

With the onOff technique, you could still have it reporting data, for instance.

But yeah, if all you want to do is turn it off, if (enabled) is the most streamlined.