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;
}
↧