• 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
0
Question by AnthMurphy · Feb 14, 2017 at 06:28 AM · unity 5javascriptobjectsrenderer.enabledhiding

Hiding and showing multiple objects

How do I write a script that can cycle through $$anonymous$$ding and showing of five objects. I've tried using GameObject.Find(Torso1) to find my objects and then renderer.enabled to $$anonymous$$de and show it, not sure if i'm heading in the right direction. The script is attached to my camera.

At the moment my error message is "The name '$$anonymous$$de' does not denote a vaild type ('not found').

Any help would be much appreciated.

Thanks:)

 var show : GameObject;
 var $$anonymous$$de : GameObject;
 private var myInt: int = 1;
 private var visible: boolean = true;
 
 function Update() {
 
     if (visible == true){
         if (Input.GetKeyDown(KeyCode.D))
         {
             myInt++;
         }
 
         if (Input.GetKeyDown(KeyCode.A))
         {
             myInt--;
         }
         if (myInt == 1)
         {
             show = GameObject.Find(Torso1);
             //show = GetComponent.<$$anonymous$$de>();
             show = renderer.enabled = true; 
         }
         if (myInt == 2)
         {
             $$anonymous$$de = GameObject.Find(Torso1);
             $$anonymous$$de = GetComponent.<$$anonymous$$de>();
             $$anonymous$$de.enabled = false;
             show = GameObject.Find(Torso2);
             //show = GetComponent.<$$anonymous$$de>();
             show = renderer.enabled = true;
         
         }
         if (myInt == 3)
         {
             $$anonymous$$de = GameObject.Find(Torso2);
             $$anonymous$$de = GetComponent.<$$anonymous$$de>();
             $$anonymous$$de = renderer.enabled = false;
             show = GameObject.Find(Torso3);
             //show = GetComponent.<show>();
             show = renderer.enabled = true;
         
         }
     }
 }

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

1 Reply

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

Answer by nbarber20 · Feb 14, 2017 at 09:00 AM

T$$anonymous$$s Should work.

Some T$$anonymous$$ngs to look up: https://unity3d.com/learn/tutorials/topics/scripting/arrays

         var VisObjects : Transform[];   // T$$anonymous$$s is an Array, t$$anonymous$$nk of it as a list.
         private var SelectedInList: int = 0;
         
         function Update () {
             
             if(Input.GetKeyDown(KeyCode.D))
             {
                 SelectedInList++;   
                 if(SelectedInList>VisObjects.length-1){// go back to the beginning of list if i try and go above the last item.
                     SelectedInList =0;
                 }
                 ChangeVis();        
             }
             if(Input.GetKeyDown(KeyCode.A))
             {
                 SelectedInList--;
                 if(SelectedInList<0){   // go back to end of list if i try and go below the first item.
                     SelectedInList =VisObjects.length-1;
                 }
                 ChangeVis();
             }
         }
     
     //runs through the entire list and makes everyt$$anonymous$$ng on it invisible, then makes the single object you have selected visible.
         function ChangeVis(){
             for(var i:int; i<VisObjects.length;i++){
                 VisObjects[i].transform.GetComponent.<Renderer>().enabled =false;
             }
             VisObjects[SelectedInList].transform.GetComponent.<Renderer>().enabled =true;
         }
 
 
 
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 AnthMurphy · Feb 15, 2017 at 03:04 PM 0
Share

Worked perfectly :)

Thanks for your help

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Script sets color to multiple objects from instead of only one object with Random.range() 0 Answers

Animation depending on the Int value 0 Answers

Hi I am trying to assign gameobject (prefab) from the List to another prefab gameobject but i think there is some mistake in one line of my code Please help. 1 Answer

Communication between WebGL and .jslib 1 Answer


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