Show and Hide 3D Objects Array by Clicking Button Over and Over
Hi everyone, This is my first time to ask in this forum. Currently, I'm still learning C# on Unity and I encounter a problem.
In my project, there are several GameObjects which are 3D models. I want to have them show only one by one just by clicking a button. (i.e. first click to show cube A, second click to show cube B, etc) and hide the rest of objects.
My scenario is to add those GameObjects as arraylist and use loop to show/hide them automatically. But, I stuck. Here's my current code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class objectChanger : MonoBehaviour {
public ArrayList arrayCube = new ArrayList();
public int totalCube;
// Use this for initialization
void Start () {
for (int i = 0; i < totalCube; i++)
{
arrayCube.Add(GameObject.FindGameObjectWithTag("ArrayCube"));
}
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Z))
{
// show
for (int i = 0; i < totalCube; i++)
{
arrayCube[i].GetComponent<Renderer>().enabled = true;
arrayCube[i + 1].GetComponent<Renderer>().enabled = false;
}
}
}
}
Anyone here can guide me here? Thanks before :)
hey @falfistrife , have you solve this problem? im stuck with the same problem and thought it will be nice if you can share the solution, if you already have one. thanks
Hey there, I´m stuck with the same problem, if you solved, can you share with us?
Your answer
Follow this Question
Related Questions
Array of buttons , and get their IDs 0 Answers
Sprite change doesn't work in built game. 0 Answers
Hold touch button Unity Javascript 1 Answer
UI Buttons Trigger displaced after build. Help Please 0 Answers
Make button move character? 1 Answer