Hello all!
Just for the life of me haven’t been able to figure out what’s wrong with my code (considering I just copied then modified from another object that does the same thing but work correctly). It uses two codes. One to detect when the player is within range, and the other to put up the popup box and then load the level. The level load works correctly, but the box is always there instead of like the other boxes how it comes and goes based on my range to the object. I wasn’t sure if maybe I put it on another object or not, so I deleted the script, it went away, and then I re-did the script only to find it doing it again. Here are my scripts:
Display GUI Script_FlyingGame.js:
var target : Transform;
function Update (){
var other = gameObject.GetComponent(“GUI Style Script_Flying Game”);
if(Vector3.Distance(target.position, transform.position) > 5) {
other.enabled = false;
}
else if(Vector3.Distance(target.position, transform.position) < 5) {
other.enabled = true;
}
}
GUI Style Script_FlyingGame.js:
var target : Transform;
function Update (){
var other = gameObject.GetComponent(“GUI Style Script_Flying Game”);
}
function OnGUI() {
//Make a background box
GUI.Box (Rect (400,400,300,90), “Do you want to play the Flying Game?”);
//Make the first button. If it is pressed, Application.Loadlevel(“Flying Game”) will be executed
if(GUI.Button (Rect(450,450,80,20), “Yes”)) {
Loading_Screen.LoadingScreenOn = true;
Application.LoadLevel(“Flying Game 2”);
}
if(GUI.Button (Rect(600,450,80,20), “No”)){
“GUI Style Script_Flying Game”.enabled = false;
}
}
I really appreciate the help. I try to fix things when I can, but it’s been about a week of trying to find this problem to no avail.
Edited to include script names for clarity