- Home /
The question is answered, right answer was accepted
OnGUI Script Not Working With Boolean...
Hey guys, another durpy question, but after trying to get a notification to pop up if you are in range of an object for several hours, I decided I needed to look into it. Even though this script brings up no console errors, the boolean will not change when the Player enters the Collider area. And yes, I have made sure that the Player Game object is Tagged. Any help would be appreciated!!!
var gui : boolean = false;
function OnGUI(){
if (gui == true){
GUI.Label (Rect (10, 10, 100, 20), "Press E to Add To Inventory");
}
}
function OnTriggerEnter (myTrigger : Collider) {
if (gameObject.tag == "Player") {
gui = true;
}
}
function OnTriggerExit (myTrigger : Collider) {
if (gameObject.tag == "Player") {
gui = false;
}
}
Agh, F*** You Fattie!!! At least Codecranker tried. >:P
Answer by codecranker · May 10, 2013 at 03:29 AM
Are you sure OnTriggerEnter is getting called? If you put a breakpoint on line 10, does it break there?
Or if you put Debug.Log(other.gameObject.tag); inside OnTriggerEnter() what does it print in the console?
Actually, I tried that earlier, but this does not produce any console messages- I am wondering if this is even something wrong with my script...? Actually, can someone reopen this? I never marked this as correct, and it did not solve the problem.
Well, if it doesnt produce any console messages that means OnTriggerEnter/Exit is not getting called. Did you forgot to check the 'IsTrigger' checkbox on your gameObject's collider?
You can look and compare in the table at the bottom of the page to be sure when the the trigger events are called http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
Actually, yes, I did. $$anonymous$$aybe you should try the script in a unity project and tell me if it works for you...?
I dont think so simply adding the script in unity will work. I need to know how your scene is setup and to which gameObject you attached the script to. It might be that your object positioning is wrong or misplaced.
I attached the script to a cube with a rigidbody, 1 other collider (For Physics) and the only other thing interacting with it is th terrain and the player. This is a prototype scene, just trying to get this to work. XP
Follow this Question
Related Questions
Using Time with OnGUI Help 2 Answers
If...else statement with errors 1 Answer
Better way to delay a function for a few seconds? Javascript 1 Answer
Change Variable on Another Script 2 Answers
I need some help on inventory. 0 Answers