- Home /
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).
GameObject.Find("Terrain").GetComponent("TerrainScript").enabled=false;
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.
Answer by Cyclops · May 21, 2010 at 02:38 PM
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) {
Debug.Log("wups");
}
// 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?
Uhm, this is interesting... but I can't understand why. If somebody wants to stop a script why it's not possible to do that completely?
@GODLI$$anonymous$$E, as @Duck pointed out to me (wish I could find it again), it enables the script to be re-enabled by mouse-click. If the script stopped responding to everything, and you wanted it re-enabled, then some other Object would have to read mouse-clicks, find the script, and enable it. Way too complex.
Answer by Lucas Meijer 1 · May 07, 2010 at 11:25 AM
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.
Your answer
Follow this Question
Related Questions
Disable SCRIPT HELP!!!! 1 Answer
How do I disable a wind zone through script? 2 Answers
Turn Off/on culling mask by script? 2 Answers