Good morning, all. Happy Friday.
I am trying to combine to aspects of a scene I have into a more streamlined version. Right now I have a function that will enable/disable a mesh in my scene on a GetKeyDown input. I also have a simple gui that will send me to another scene. Each scene has the gui function so you can navigate between any scene in the project.
So what I have been trying to do ( and failing at so far this morning ) is to set up a gui with a series of buttons, that when pressed, will toggle a mesh on and of.
The closest I can figure it, is I’d have to set a var:GameObject so I can choose which game object I want this to happen to. Then something like if (Gui.Button (Rect (10,10,50,50), “Render Mesh”)) {
- then i don’t know what would go here- ;
}
So as you can see. I’m at a total loss on this. Just trying to get this done by the end of the day so I can go visit the grandparents ( 5 hour drive ) .
Here’s what I have to work with.
function OnGUI () {
GUI.Box (Rect (10,10,100,90), "Turn Stuff On and Off");
if (GUI.Button (Rect (20,40,80,20), "Object 1")) {
This is where the enabling/disabling would have to go;
}
if (GUI.Button (Rect (20,70,80,20), "Object 2")) {
This is where the enabling/disabling would have to go;
}
}
And here is what I have been using to turn it on and off
function Update () {
if (Input.GetKeyDown ("2"))
renderer.enabled = !renderer.enabled;
if (Input.GetKeyDown ("2"))
renderer.disabled = !renderer.disabled;
}
So in short ( too late ) I am wanting to do away with pressing a button to get the mesh on and off and make that a function of a button in my GUI. And I want to be able to set the objects as variables so I can utilize this script for many different objects, thus streamlining the project and making it much more user friendly.
So any help at all would be greatly appreciated. Anything. Can’t keep grandparents waiting!
Thanks a ton in advance, all.
-Richard