• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by AdamEstone · Aug 08, 2011 at 10:50 PM · pausedisableenable

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?alt text

 // 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!!! :-/

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
Best Answer

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

Comment
Chris D
kiwi koder
gretty

People who like this

3 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AdamEstone · Aug 08, 2011 at 11:29 PM 0
Share

"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 cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)

it say it is at that line with: ...FPSWalker.enabled = false;

avatar image SisterKy · Aug 08, 2011 at 11:33 PM 1
Share

thanks for turning this into a comment instead 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;

avatar image TomatoOrgyLT · Jan 26, 2013 at 08:49 PM 0
Share

When I try to do this I get an error message saying BCE0019: 'GetComponent' is not a member of 'UnityEngine.GameObject[]'. Why?

avatar image sona.viswam · Mar 08, 2013 at 12:07 PM 0
Share

its not working. then how will you check it as correct answer?

avatar image

Answer by Tknoguyfication · Mar 20, 2014 at 06:33 PM

It's easier to do time.Timescale = 0;

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Script Not staying disabled 2 Answers

Turn Off/on culling mask by script? 2 Answers

disable/enable mouselook not working? 1 Answer

Enable/Disable GameObject Button script 1 Answer

disable/enable script js 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges