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 mcarney82 · Aug 12, 2013 at 09:37 PM · arrayhideshowrenderer.enabled

Can you use renderer.enabled on array members ?

Hello I am a beginner so I'm not sure if this is possible.

I am instantiating a column of cubes and I am trying to show / hide each member based on a value.

Each member of the array is the same prefab.

In this code all 5 blocks are showing, even though I only have renderer.enabled true on the second member.

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class PlantStats : MonoBehaviour {
public GameObject[] moisHealth; public GameObject[] tempHealth; public GameObject[] lightHealth;

 private float xDirection      = -0.24f,
               moisYDirection  =  0.24f, 
               tempYDirection  =  0.24f,
               lightYDirection =  0.24f,
               zDirection      = -0.07f,
               moisGrowAmount  =  0.09f,
               tempGrowAmount  =  0.09f;

 private int moisHealthChecker = 0,
             moisArrayValue    = 0,
             tempArrayValue    = 0,
             lightArrayValue      = 0,
             plantHealth          = 0,

// sensor values moisSensorValue = 0;

 void Start () 
 {    
     PopulateMoisture();
     PopulateTemp();
     PopulateLight();    
 }

 void Update () 
 {
     if (Input.GetKey(KeyCode.Alpha1)) 
     {
        moisHealth[0].renderer.enabled = true;
     }
     
 }
 
 void PopulateMoisture()
 {

     for (int i = 0; i<=4; i++)
     {
         Vector3 cubeMoisPosition = new Vector3(transform.position.x + xDirection, transform.position.y + moisYDirection, transform.position.z + zDirection);
         GameObject newMoisture = Instantiate(moisHealth[moisArrayValue], cubeMoisPosition, transform.rotation) as GameObject;
         moisYDirection = moisYDirection + moisGrowAmount;
         moisArrayValue++;
     }    
     
     moisHealth[0].renderer.enabled = false;
     moisHealth[1].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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Aug 12, 2013 at 09:39 PM

You have coded it. Have you tried it? If the question is, can I do this kind of thing:

moisHealth[0].renderer.enabled = false;

yeah, sure.

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 TimBorquez · Aug 13, 2013 at 12:33 AM

yup if your array members have a renderer component you can access it

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 mcarney82 · Aug 13, 2013 at 11:59 AM

OK thanks a lot guys. Now that I know I can...

I'll have to see why it's not working in my above code.

I am currently saying

moisHealth[0].renderer.enabled = false; moisHealth[1].renderer.enabled = true;

but moiseHealth[0] IS rendering.

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

17 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

Related Questions

Unity 2019.4.9f1 - Toggle Show/Hide Gameobject with one keystroke. 1 Answer

on collision, show/hide other model scripting ? 1 Answer

Why not showing up 1 Answer

[FIXED & CLOSED!] How do I show and hide 3D text? 2 Answers

Re-hiding a guiTexture 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