- Home /
Disabled Script Enables Itself
Hey guys. The script below is something I made real quick. I disabled the script in the inspector, and made it so it turns itself on when an OnMouseDown function is executed. Basically what I want is so the script can't activate until called by another script. Is there any way I can make it so I can press my mouse button down and the script can't enabled itself?
Answer by zach-r-d · Aug 04, 2015 at 11:11 AM
OnMouseDown will be called even on disabled scripts, just like OnCollision or OnTrigger events. To prevent execution the function when the script is disabled, it's possible to check if the script is enabled at the beginning of the function, and return immediately if not:
void OnMouseDown() {
if (!enabled)
return;
// execute real stuff here
}
Your answer

Follow this Question
Related Questions
Progresive sound ? 1 Answer
Function not valid macro 1 Answer
Help with OnTriggerEnter and mouse down 2 Answers
javascript to unity javascript conversion 1 Answer
I got a bunch of errors that make no sense to me. Help. 2 Answers