I am having MAJOR trouble with my buttons. I thought maybe it had something to do with my GUI, but now I think it is a variable problem.
I have the code below attached to a game object, where the button “changer” is the left ctrl, which switches camera views. However, all of my GUI buttons also cause this code to run, AND I HAVE NO IDEA WHY!! Could pressing the GUI buttons somehow be changing the variable “switcher” I am using in the code below?
var fpsCam : GameObject;
var orientationCam : GameObject;
var fpsMaterial : Material;
var orientationMaterial : Material;
var modelUse : GameObject;
var orientationLight: GameObject;
var orientationLight1: GameObject;
var pointLight: GameObject;
private var switcher : boolean = false;
orientationLight.active = false;
fpsCam.active = true;
orientationCam.active = false;
orientationLight1.active = false;
pointLight.active = false;
function Update () {
if (Input.GetButtonDown("Changer")) {
switcher = !switcher;
if (switcher == true) {
modelUse.renderer.sharedMaterial = orientationMaterial;
fpsCam.active = false;
orientationCam.active = true;
orientationLight.active = true;
orientationLight1.active = true;
pointLight.active = true;
}
else {
modelUse.renderer.sharedMaterial = fpsMaterial;
fpsCam.active = true;
orientationCam.active = false;
orientationLight.active = false;
orientationLight1.active = false;
pointLight.active = false;
}
}
}
This is the code for my GUI buttons:
function OnGUI()
{
// Make a background box
GUI.Box (Rect (0,Screen.height - 50,Screen.width,75), "Informative text");
// Make a button.
if (GUI.Button (Rect (Screen.width - 100, Screen.height - 45,80,20), "Test")) {
print ("You clicked the button!");
}
}
I have been wracking my brain, trying to think of what the problem is, but I am completely stumped. Any input would be much appreciated!