In my game, I have two different game objects for the water. One setting is simple, and doesn’t drain performance. The other is heavy on the CPU. What I want to do is make a button that, when clicked, switches between the game objects, so the player can choose what he/she wants to use. I am a novice coder however, and I can’t figure out how to get it working.
Here’s my code:
#pragma strict
var water1: GameObject;
var water2: GameObject;
public var triggered : boolean = false;
function Start () {
water1 = GameObject.Find("water");
water2 = GameObject.Find("Ocean");
}
function OnGUI () {
// GUI.Box(Rect(100,100,600,400),"");
if(GUI.Button(Rect(Screen.width - 100,Screen.height - 50,100,50),"Super Water ON/OFF"))
{
if(triggered = false)
{
water1.active = false;
water2.active = true;
triggered = true;
}
else
{
water1.active = true;
water2.active = false;
triggered = false;
}
}
}