Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by NutellaDaddy · Mar 26, 2014 at 11:48 AM · c#disableenable

How can I enable and disable scripts at runtime?

Im trying to disable two different scripts during runtime, in this case I need to diable the mouse Look and playerMovementV1 script on the player object. How would I do this?

Comment
Add comment · Show 1
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 Fornoreason1000 · Mar 26, 2014 at 11:58 AM 0
Share

this question has been answered and asked many times. first you get the refernce of the component and set its enbaled to false;

 (gameObject.GetComponent("$$anonymous$$ouseLook") as $$anonymous$$ouseLook).enabled = false;

http://answers.unity3d.com/questions/26844/enabledisable-specific-components.html http://answers.unity3d.com/questions/649162/how-to-enable-and-disable-script.html http://answers.unity3d.com/questions/28362/find-gameobject-and-activatedeactivate-it.html http://answers.unity3d.com/questions/672694/unable-to-enable-script.html http://answers.unity3d.com/questions/433018/enable-disable-object-script-error.html http://answers.unity3d.com/questions/529866/disable-gameobject-at-other-screen-with-code-.html

didnt even use google.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Punkjim420 · Mar 26, 2014 at 11:57 AM

http://answers.unity3d.com/questions/39748/disable-script-from-code.html

Comment
Add comment · Show 3 · 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 Punkjim420 · Mar 26, 2014 at 12:02 PM 0
Share

ahhh thats unityscript. for c# youd do something like this:

 public Player playerScript;

and then

playerScript.enabled = false; in your code somewhere like an if statement maybe.

avatar image Fornoreason1000 · Mar 26, 2014 at 12:04 PM 0
Share

@Pumkjim420 yeah you need to get the reference of the code using GetComponent first. otherwise you would just get a null reference error because player Script isn't equal to anything, its null until you assign it.

avatar image Punkjim420 · Mar 26, 2014 at 12:07 PM 0
Share

ah ok, then i stand corrected. I usually use bools to disable lines of scripts anyways. ;)

avatar image
0

Answer by hdr25 · Jan 12, 2017 at 09:21 AM

Things are different now in Unity 5 Its simple .. First you have to get that component and then get access to its script..

GameObject.FindGameObjectWithTag ("YOUR GAME OBJECT").GetComponent ().enabled = false;

Comment
Add comment · Show 1 · 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 tanoshimi · Jan 12, 2017 at 11:06 AM 0
Share

That's exactly the same as it has been in previous versions of Unity, and as was already answered nearly 3 years ago...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

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

Related Questions

Enable/Disable Game Object With GUI Button 1 Answer

Enabling loop and disabling loop 1 Answer

[solved]how can i enable or disable a component of instantiated objects? 5 Answers

error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3 Answers

image not enabling 0 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