- Home /
Disable a script from another script
Hello,
I have a problem: i can't disable a script from an other script. why? I am making a menu, and i want to stop my player moving, when it is on pause. Or is there an other way to do it?
// the var 'P' = pause
static var P=0;
function Update () {
// i did define the escape button!
if(Input.GetButtonDown("esc")){
P=1;
}
}
function OnGUI()
{
if (P==1){
Screen.showCursor = true;
GUI.Box(Rect(-45,0,2000,1000), "Pause");
if(GUI.Button(Rect(910,300,100,30), "Resume")){P=0; Screen.showCursor = false;}
if(GUI.Button(Rect(910,500,100,30), "Exit")){Application.Quit();}
/*Error-->*/ gameObject.Find("FirstPersonControllerPrefab").FPSWalker = false;
/*Error-->*/ gameObject.Find("FirstPersonControllerPrefab").FPSWalker.enable = false;
/*Error-->*/ gameObject.Find("FirstPersonControllerPrefab").FPSWalker.false;
/*Error-->*/ gameObject.Find("FirstPersonControllerPrefab").FPSWalker.active = false;
}
}
Please help! ASAP!!! :-/
Answer by SisterKy · Aug 08, 2011 at 11:20 PM
Try ...FPSWalker.enable*d* = false; If that still gives an error, please tell us what it's saying
"If that still gives an error, please tell us what it's saying"
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
it say it is at that line with: ...FPSWalker.enabled = false;
thanks for turning this into a comment ins$$anonymous$$d of an answer :)
oh, stupid me! How did I miss this? shakes her head! Sorry... Of course. you have to use
gameObject.Find("FirstPersonControllerPrefab").GetComponent(FPSWalker).enabled = false;
When I try to do this I get an error message saying BCE0019: 'GetComponent' is not a member of 'UnityEngine.GameObject[]'. Why?
its not working. then how will you check it as correct answer?
Your answer
Follow this Question
Related Questions
Disable SCRIPT HELP!!!! 1 Answer
Script Not staying disabled 2 Answers
Turn Off/on culling mask by script? 2 Answers