Weird Variable/Button problems

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!

Should be fine. What happens if you use something other than left ctrl? Do you have any third-party utilities that might be making a mouse button click send a left ctrl event?

–Eric

It does the same thing with any other key I assign! I don’t have any third party utilities installed–in fact I’ve tried it on 2 different computers and it does the same thing! I’m completely stumped! :?

Maybe post the project, preferrably a cut-down version that just shows the problem? I can’t see anything in the script that would do that.

–Eric

Thanks so much for the help Eric!

It’s the “camera switcher” script that is problematic.

It’s the “Alt Positive Button” that cause the problem, i think.

I tried Edit->Project Setting->Input

and delete the “mouse 0” of the “Switch” in “Alt Positive Button” and seems working.

You’re right!! This fixed the problem!!! Thanks!

:smile: :smile: :smile: :smile: :smile: :smile: