Disabled Script still does OnMouseDown


I have a script with two functions in it, an Update and an OnMouseDown.

When I disable it, the code in the Update no longer runs, but the code in the OnMouseDown is still working.

Is this by design? And if so, why?


Disabling a script only disables Update and similar functions (including OnGUI), but not much else. This is by design; it's not a bug. That way you can prevent scripts from using CPU time with Update when not needed, but use other functions to re-enable them or perform other functions if necessary.

If you need other functions aside from Update etc. to be disabled too, use this code:

function OnMouseDown () {
    if (!enabled) return;
    // rest of code