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 Hexer · Feb 16, 2014 at 09:11 PM · javascriptgameobjecthierarchyenable

Enable GameObject in Hierarchy with Script

I have a problem and I can't find the solution, I hope you guys can help me out.

I am trying to enable a gameobject in the hierarchy.

I use this Javascript for it. I assign the meshes to the vars. and let the script pick randomly one of the 5 path-layouts for the puzzle. (so the gameobjects are by default disabled in the hierarchy) Now i want to enable them with this script. However it doesn't seem to work. So can someone check my script? I have the feeling there is something wrong with this line. Green.enabled(true);

 //Mesh of the right Maze.Path.gameobject
 var Green : GameObject;
 var Red : GameObject;
 var Blue : GameObject;
 var Yellow : GameObject;
 var Brown: GameObject; 
 
 //randomize the puzzle Layout
 function RandomMaze()
 {
     var randMaze = Random.Range(0, 4);
     var chosenLayout = randMaze;
     
     switch (chosenLayout)
     {
         case 0:
             Green.enabled(true);
         break;
         case 1:
             Red.enabled(true);
         break;
         case 2:
             Blue.enabled(true);
         break;
         case 3:
             Yellow.enabled(true);
         break;
         case 4:
             Brown.enabled(true);
         break;        
     }
 }

alt text

I appriciate your help. Thanks

problem.png (304.7 kB)
Comment
Add comment · Show 4
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 thaiscorpion · Feb 16, 2014 at 09:29 PM 0
Share

Try using SetActive

 Green.SetActive(true);


avatar image Hexer · Feb 16, 2014 at 09:38 PM 0
Share

Thanks for your help, but it didn't solve the problem

avatar image DajBuzi · Feb 16, 2014 at 09:43 PM 1
Share

I think that .enabled is only for components and .SetActive is for GameObject

Try this:

 Green.activeinHierarchy = true;
avatar image Hexer · Feb 16, 2014 at 09:49 PM 0
Share

Still, no change :( but i will keep trying to find the solution. Thx

Update : I am now looking at "https://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActive.html"

"Note that a GameObject may be inactive because a parent is not active. In that case, calling SetActive() will not activate it, but only set the local state of the GameObject, which can be checked using GameObject.activeSelf. This state will then be used once all parents are active."

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

How to deactivate something when holding down a key? 1 Answer

enable and disable boxcollider (whats wrong with my script?) 2 Answers

How to tell if 2 blocks are next to each other in a 2d game? 1 Answer

OnCollisionEnter Collision not detected? 1 Answer

Unity IDE: Finding out object type of arbitrary item in Hierarchy 3 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