|
Hi. This is my first attempt at coding with javascript in Unity and I've run into difficulty with what I think should be a relatively simple task. I have three objects in the scene and I want to control their visibility using three GUI buttons, one for each object. I need it to work so that each button makes an object visible while making the other two invisible. I have so far got the following script attached to my scene camera: Using this I am not getting the behaviour I had hoped for. Ideally, the button named "Blue" would make the "Sphere-Blue" object visible while blocking out the other objects. Am I even close? Searching the forums has got me to this point but I'm feeling pretty lost now. Any help would be greatly appreciated. Kind Regards
(comments are locked)
|
|
Hi. Yes, "Sphere-Blue" "Sphere-Green" and "Sphere-Red" are the names of the objects I have in the scene, though I'm not sure about the renderer? I haven't attached any renderers, I'm not even sure what that means.
(comments are locked)
|
|
Add this script:
Now, clicking on the gui button should do the trick. Renderer is the component that draws a 3D object in your game. Hey, thanks for the help. I'm stubling my way through your script and will post when I think I've got past most of the more stupid questions I have.
Apr 18 '12 at 09:02 AM
eyeproductions
No problem mate. I have added comments to the script.
Apr 18 '12 at 09:28 AM
GuyTidhar
I struggled to follow the steps and got dozens of errors. I'm not even sure where to start with describing them all. Is there a more simple way to do this?
Apr 18 '12 at 09:40 AM
eyeproductions
Have you tried placing this script in your scene following my instructions without touching the script itself?
Apr 18 '12 at 09:47 AM
GuyTidhar
(comments are locked)
|

you OnGUI() currently does only this:
You have one "name" variable, and you accessing the same renderer every time, so only the last ones actually count.
You need to reference each of your objects.
Is "Sphere-Blue" a name of an actual GameObject in your scene on which a renderer is attached?
Hi.
Yes, "Sphere-Blue" "Sphere-Green" and "Sphere-Red" are the names of the objects I have in the scene, though I'm not sure about the renderer? I haven't attached any renderers, I'm not even sure what that means.
Check out the script and the notes I listed at the bottom.