- Home /
Enter Trigger, display Text, then delete object
I am a noob at this stuff, only been doing a little while and i found a script that will display text one the Tag="Player" enters into the box collider, now it worked great.
It displays it in the center and lets me close it, but the only issue is that every time i walked into it it would pop up and i had to click close, over and over.
So i tried to add a delete function, it did delete it but the problem is it deletes it before it even loads the text to read.
var player : GameObject;
private var bool : boolean;
function OnTriggerEnter(other : Collider) {
if(other.tag == "Player") {
bool = true;
Destroy(gameObject);
}
}
function OnGUI(){
if(bool == true) {
if(GUI.Button (Rect (500, 300, 500, 80), "You can move by pressing the W,A,S,D Keys\nPress Space Bar to Jump, (E) Key is Action!\n\n[Click to close]")) {
bool = false;
}
}
}
So it keeps deleting it before i can ever display it, or i move it and nothing happens anyone know what i am doing wrong thanks.
Edit: I was told a button is not a good way but i don't know anyone other way to achieve this, i wanted to make it check to see if a box was already open but did not work maybe you experts can offer an alternative?
Answer by Slobdell · Jun 30, 2013 at 07:08 PM
You're destroying it when it enteres the collider, try this
var player : GameObject;
private var bool : boolean;
function OnTriggerEnter(other : Collider) {
if(other.tag == "Player") {
bool = true;
}
}
function OnGUI(){
if(bool == true) {
if(GUI.Button (Rect (500, 300, 500, 80), "You can move by pressing the W,A,S,D Keys\nPress Space Bar to Jump, (E) Key is Action!\n\n[Click to close]")) {
bool = false;
Destroy(gameObject);
}
}
}
Ok thanks, it looks like it worked i exited the collider and walked back in and it did not appear again thanks.
Is there a way to make it check if there is already a window open? I noticed it keeps stacking up over each other.
There should only be one. $$anonymous$$akes me think you either have the script attached more than once to the same object, attached to multiple objects, or multiple of the same object in the scene. It will show up once for each script that is active somewhere.
Yeah i do i have it attached to different signs, is there a way to define it in the script above for multiple objects? or by Tag ID?
Well what's the purpose of this? I'm assu$$anonymous$$g the message above is just for the first time they start playing and then it never shows again. What messages are supposed to pop up and when/why?
I guess it would help what i am using it for sorry, So when a player is walking along he/she will trigger a Sign(Collider) that will display a message. The first one is below the Player>Controller so when it lands (on play) it will pop up with the control info. then i have them along special points to give them Tip's and Helpful info.
Does that make sense lol? Like a Tip System, i thought by making each script with my code it would work, but as you pointed out it should only display one but because i have it set up half a** it don't work > Noob
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Only access door if it's not locked? 1 Answer
Script outdated i think, Unity 4 - Compiler errors galore 1 Answer
What is wrong with my RockPaperSissors script? 1 Answer
error cs0120 1 Answer