Script Not staying disabled

Has anyone else come across this? A script that I disable with the code below disables for an instant, then doesn't stay disabled any longer (I know this by debugging).


I don't have it being enabled anywhere in my code and I can't figure out why it becomes enabled again. TerrainScript does have a Update function but I can't imagine that making a difference.

For debugging purposes, one thing I like to do is break down any multiple-step statements, and check that every step worked. For instance, you could do:

var foo = GameObject.Find("Terrain");
if (foo == null) {
// then get Component next, etc...

It's possible that something is breaking somewhere (maybe mispelling/typo), and it's not obvious.

Also - what do you mean by not disabled? I can't find the Answer again, but I remember Duck posting somewhere, that disabling a script only disables certain functions, like Update(), etc. Some things - specifically OnMouseUp(), for instance, stay enabled, and so the script will respond to mouse clicks.

Is that what's happening?

The only thing I could think of is that your code somewhere is in fact enabling it again, without you realizing it. Try putting the terrain and this script in a seperate scene, and see if it still happens.