- Home /
When I go inside a collider I want GUI Text to appear, and allow me to press 'e' to swap scenes, but it instantly transports me to the scene.
When I go inside a collider I want GUI Text to appear, and allow me to press 'e' to swap scenes, but it instantly transports me to the scene. I've tried but it doesn't work, heres my script:
#pragma strict
private var AllowBasement;
function OnTriggerEnter()
{
AllowBasement = true;
}
function OnTriggerExit()
{
AllowBasement = false;
}
function OnGUI()
{
if(AllowBasement == true);
{
GUI.Box(Rect(0, 0, Screen.width, Screen.height), "Press 'e' to go to the basement");
}
}
function Update () {
if(AllowBasement == true);
{
if (Input.GetKeyDown("e"));
{
Application.LoadLevel("Basement");
}
}
}
When I use this script the game automatically transports me to basement, Help?
Thanks! That worked, sorta, but now I can press e anywhere and it transports me? Any help?
Thanks!!! Its all working now, Thank you $$anonymous$$rSoad, could you tell me how to mark this as answered?
I've converted it to an answer for you to accept, glad it sorted out your problem. The only real difference between what I did and what tanoshimi did is the initialization of your AllowBasement bool, which prob defaulted to true and so you could press e anywhere as the previous condition was met on start up.
Answer by MrSoad · Nov 20, 2014 at 12:26 PM
Give this a try and let me know if anything improves, the only real thing that I change is the way the if statements are written, along with a proper declaration of you AllowBasement boolean and its initialization :
#pragma strict
private var AllowBasement : boolean;
function Start() {
AllowBasement = false;
}
function Update() {
if (AllowBasement == true) {
if (Input.GetKeyDown("e")) {
Application.LoadLevel("Basement");
}
}
}
function OnTriggerEnter() {
AllowBasement = true;
}
function OnTriggerExit() {
AllowBasement = false;
}
function OnGUI() {
if (AllowBasement == true) {
GUI.Box(Rect(0, 0, Screen.width, Screen.height), "Press 'e' to go to the basement");
}
}