I need to make a script on an object change a variable in a script on a camera. I’ve read countless answers via google and I think I’m close to getting it to work but I can’t quite get it to happen. Can anyone tell me what I’m doing wrong? Here’s what I’ve got (javascript):
The variable in a script on my main camera:
public static var variableInTheCameraScript = false;
The script on the object:
var findCamera : GameObject;
var getScript : MonoBehaviour;
function Start(){
findCamera = GameObject.Find("Main Camera");
getScript = findCamera.GetComponent(ScriptOnTheCamera);
}
function OnGUI(){
if (Input.GetMouseButtonDown(0)){
getScript.variableInTheCameraScript = true;
}
}
This gives me the error “variableInTheCameraScript is not a member of UnityEngine.MonoBehaviour.”
I’ve also tried changing getScript to a boolean and using:
findCamera.GetComponent.getScript.variableInTheCameraScript = true;
Which gives the error “getScript is not a member of function(System.Type): UnityEngineComponent”