• 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
0
Question by phatpixels · Oct 21, 2015 at 09:54 AM · script.setactiveenablefalsetrue

script enable=false

Hello All, I have been looking up and down for a simple jscript to disable a script on another object. Seems active or enabled doesnt work in function update unless im missing something which im sure might be the case as im relatively new to scripting. If someone has a hint or script i could follow for unity5 that would be great, in the meantime i'll keep searching. Thankyou.

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

3 Replies

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

Answer by phatpixels · Oct 21, 2015 at 10:31 AM

seems i was doing it wrong....... this is correct js

 cube.GetComponent( move2 ).enabled = false;

this didnt work

 cube.GetComponent( "move2" ).enabled = false;

thankyou all for your help :-)

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 CanCo · Oct 21, 2015 at 11:18 AM 0
Share

Hey there. I see you're using JavaScript, C# runs faster on the Unity engine (JavaScript can also sometimes be faster).

To do this you should be creating a variable beforehand with cube.GetComponent("move2").

Also, C# method is:

 private move2 FOOBAR;
 
 void Start ()
 {
     FOOBAR = cube.GetComponent<move2>();
 }
 
 void Update ()
 {
     FOOBAR.enabled = false;
 }
avatar image
0

Answer by CanCo · Oct 21, 2015 at 10:24 AM

 GameObject.SetActive(bool);
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
avatar image
0

Answer by LucasVmarrewyk · Oct 21, 2015 at 10:24 AM

Hey there,

Have you tried: scriptName.SetActive(true); ?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

.setActive(true) not functioning. 1 Answer

My method is called more than once. 1 Answer

How to save Component 1 Answer

Basic Code Problem 1 Answer

How to enabled a specific gameObject in array? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges