I want to make a script that disables the character controller’s mouselook script when the player enters a trigger, but when I enter the trigger it gives this error:
Object reference not set to an instance of an object.
This is my script: (the script I want to disable is called controlgui)
private var inRange: boolean = false;
private var recttext = Rect((Screen.width-w)/2, (Screen.height-100), w, h);
var customGUI : GUIStyle;
var text1 : String;
var controller : GameObject;
var w = 250;
var h = 300;
function OnTriggerEnter(other:Collider) {
if (other.tag == "Player") {
inRange = true;
}
}
function OnTriggerExit(other:Collider) {
if (other.tag == "Player") {
inRange = false;
}
}
function OnGUI() {
if(inRange) {
GUI.Label(recttext,text1,customGUI);
}
}
function Update () {
if (inRange){
controller.GetComponent(controlgui).enabled = false;
}
}