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
0
Question by Depento · Nov 01, 2013 at 11:36 AM · arrayactivevisible

Displaying a single gameObject from an array of gameObjects

So I have an array of game objects, which I attached to a gameObject within the bounds of my camera:

 public GameObject[] storeAppliances;

The array is manually filled in from the inspector window. In the start function, this is what I have:

 for (int i = 0; i < storeAppliances.Length; i++)
         {
             storeAppliances[i].active = false;
         }

When you click on a button in the game, I have it so:

 GameObject displayItem = (GameObject)Instantiate(storeAppliances[arrayLoc], new Vector3(0,2,0), transform.rotation);
 displayItem.active = true;
 

(arrayLoc is determined by the button you press in a list of buttons, which is the same length as storeAppliances).

After another button is pressed, I change it so:

 displayItem.active= false;

I can't get the gameObject to display on the screen, and according to my Hierarchy, it isn't instantiating. I'm fairly new to unity, so I'm not sure where my mistake is made. All of the buttons are doing what they should be doing, so there is no issue there, but my code that I added to make an gameObject display on the screen is not working. If anyone could help, I would GREATLY appreciate it.

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 sethuraj · Nov 01, 2013 at 05:19 PM 0
Share

you cant work on disabled gameobjects.they wont instantiate or cannot be found using GameObject.Find().Ins$$anonymous$$d of setting the item to inactive work with the meshrenderer to hide/show it.

 for (int i = 0; i < storeAppliances.Length; i++)
 {
    storeAppliances[i].renderer.enabled=false;
 }

Dont make the object inactive if you want to use it later or you have to set it active before using.

If you dont want any object to be used again,Destroy it for better performance dont hide or make it inactive

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

16 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

Related Questions

Javascript How to Activate/Deactivate GameObject Arrays 1 Answer

A node in a childnode? 1 Answer

Modifying A*Pathfinder... 1 Answer

C# SetActive GameObject Array 2 Answers

Unity 3 GD HotShot-Tutorial Problem with an C#-Array 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