Hi, I’ve just spent the last two days trying to learn enough JavaScript to do this but cant figure it out…
I’m trying to create a couple of buttons that will hide/show various groups of objects.
eg. I’ve got a scene with 3 cubes, 3 cylinders, 3 spheres. I want 3 buttons that will toggle visability of each group.
I can get the buttons to show/hide one gameobject using var Cube : GameObject but dont know how to have a group of gameobjects effected. I’ll later want to use this script so I can hide the surfaces, buildings, or utilities of a scene.
I’ve tried arraying a group of objects or using the GameObject.FindGameObjectsWithTag but to be honest I dont really know what I’m doing or if i’m wasting my time??? Any ideas?
Here is my working script: (I guess my question really is how can I set the var CubeGroup as more than one GameObject?)
//ShowHide button script
var CubeGroup = GameObject.FindGameObjectWithTag(“Spheres”);
var Sphere : GameObject;
var Cylinder : GameObject;
function OnGUI () {
//Make a background button box
GUI.Box (Rect (10,10,100,120), “Show/Hide”);
//Hide/Show Group of Cubes
if (GUI.Button (Rect (20,40,80,20), “Cube”)) {
CubeGroup.renderer.enabled = !CubeGroup.renderer.enabled;
}
//Hide/Show 1 Sphere
if (GUI.Button (Rect (20,70,80,20), “Sphere”)) {
Sphere.renderer.enabled = !Sphere.renderer.enabled;
}
//Hide/Show 1 Cylinder
if (GUI.Button (Rect (20,100,80,20), “Cylinder”)) {
Cylinder.renderer.enabled = !Cylinder.renderer.enabled;
}
}