Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
1
Question by VLunarFangV · Aug 24, 2015 at 07:30 PM · javascriptdisable

Disable script using another script

Yeah, how do I do that?

Comment
Add comment · Show 5
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 VildNinja · Aug 24, 2015 at 07:39 PM 1
Share

There are multiple ways. Once you have a reference to the script you can call otherScript.enabled = false; to disable the update loop in the script. Please specify an example on how/when this should happen, if you want a better answer.

avatar image Political Peace Party Studios · Sep 01, 2015 at 08:33 AM -1
Share

Hello, if my answer was correct please help me as well,and other people having the same issue by selecting my answer as correct. Thank you!

avatar image VLunarFangV · Sep 01, 2015 at 12:02 PM 1
Share

Sorry, I've been busy and haven't managed to respond. It has worked well in $$anonymous$$onoDevelop, however in Unity, I'm still getting "scriptname" is an unknown identifier, even though I followed that link you posted.

avatar image Political Peace Party Studios · Sep 03, 2015 at 08:11 AM 0
Share

Have you tried putting the C# code in a folder called "Standard Assets"? $$anonymous$$ake a folder in Assets called Standard Assets. So thats Assets/StandardAssets. Put the C# code in there then try using the code below and let me know what happens.

avatar image VLunarFangV · Sep 05, 2015 at 11:46 PM 0
Share

I have moved the C# script into Standard Assets and kept the JS script in Assets. Still doing the thing.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Political Peace Party Studios · Aug 25, 2015 at 12:47 AM

Here is the code you are looking for.

   //Disable another script as soon as your press Play

   function Start () {

   gameObject.Find("gameobject").GetComponent (scriptname).enabled = false;

   }


"gameobject" = the name of the game object that the script is on in the hierarchy.

"scriptname" = the name of the script that is on the game object.

(TIP) - To turn the script back on just change the word (false) to (true).

Comment
Add comment · Show 7 · 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 VLunarFangV · Aug 25, 2015 at 04:59 PM 0
Share

I've put in the line and I'm getting ""enabled" is not a component of UnityEngine.Component".

avatar image Political Peace Party Studios · Aug 25, 2015 at 06:35 PM 0
Share

I just tested this code and it worked. You are using javascript right?

avatar image VLunarFangV · Aug 26, 2015 at 06:27 AM 1
Share

I am using JavaScript, yes. However the code I'm trying to disable is in C#, in case that made any difference.

avatar image ransomink · Aug 26, 2015 at 06:49 AM 0
Share

Please show us the code you used and the script so we can pinpoint where the error is occuring...

avatar image Political Peace Party Studios · Aug 26, 2015 at 09:21 AM 0
Share

Yes Javascript can't access the C# code that is the problem. I believe the fix would be putting the C# code in a folder called Plugins or standard assets Assets/plugins/C#code then it might work. Check this out http://answers.unity3d.com/questions/252865/accessing-a-c-field-from-javascript.html

Show more comments
avatar image
1

Answer by unpluggeDloop · Jan 31, 2020 at 01:05 AM

   void Start () {
          this.GetComponent<YourScriptName>().enabled = false;
     }

...or check yt video https://www.youtube.com/watch?v=kgOttwh8-fE

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 squirtpistol · Mar 21 at 12:04 AM 0
Share

Thank you so much

avatar image
0

Answer by Whynote · Mar 10 at 09:56 AM

 if (GameObject.Find("yourobjectname") != null) // just to avoid null pointer exceptions
         {
             GameObject.Find("yourobjectname").GetComponent<yourscriptname>().enabled = false;
         }

yourobjectname = Name of your object that has the script in it

yourscriptname = the script you want to disable (or enable by replacing "false" with "true"

Hope this helps it worked fine for me @VLunarFangV

Comment
Add comment · 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

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

30 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How read data from simulink to javascript? 0 Answers

How do you disable all controls? 0 Answers

Modify "Humanoid" Animations 0 Answers

Check renderer color of object at Vector 3 location 0 Answers

How to disable LockTexture in case of LEVEL UNLOCK SYSTEM IN UNITY? 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