- Home /
OnGUI not working?
For some reason, GUI not working when I'm on trigger? Why? This is the script of it. I used this type of script for door, pick up key, and call phone but GUI is not appear!
This script is for key
var message : boolean = false;
var LockedTrigger : Collider;
var UnlockedTrigger : Collider;
function Start()
{
LockedTrigger.enabled = true;
UnlockedTrigger.enabled = false;
gameObject.SetActive(true);
}
function OnTriggerStay(other : Collider)
{
if(Input.GetButton("e")){
gameObject.SetActive(false);
LockedTrigger.enabled = false;
UnlockedTrigger.enabled = true;
}
}
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
message = true;
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
message = false;
}
}
function OnGUI(){
if(message){
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 300, 30), "Press E to pick up Exit door key");
}
}
Are you sure message
is true in OnGUI? Could you put
print(message);
before if
statement, just for test?
The GUI in this script should work fine. However, what are you doing with LockedTrigger
and UnlockedTrigger
? are either of them attached to this gameObject? $$anonymous$$aybe one of them is attached, and you're disabling it, and thus the OnTriggerEnter
and Exit
aren't getting fired?. I have already told you here (at the end), not to use any of the Input.GetXXX
family members, inside of OnTriggerStay
.
$$anonymous$$essage is printed as false although I'm in the trigger
but I able to pick up that key
Locked Trigger will appear "Door Is Locked" GUI ... Unlocked Trigger will make players able to open it by pressing E
No, it's not attached to this key
I forgot about that.
Answer by ArkaneX · Oct 14, 2013 at 08:48 AM
If message
is false, then please check if it is properly set in OnTriggerEnter
(maybe your player object has no Player
tag set?). Additionally, you can check if OnTriggerExit
is not called.
Your answer
Follow this Question
Related Questions
enable a canvas on trigger 2 Answers
Problem with Colider/Trigger and OnGUI function 1 Answer
Trigger 'if' statement while in TextField 2 Answers
How to have OnGUI element in a OnTriggerEnter function? 3 Answers
Adding a value after a trigger on 1 Answer