- Home /
Question about pop up boxes during the game
Hey,
I would like to ask for help, maybe somebody can explain to me how I can create GUI pop up box (text, images and links), which will appear when player hits the wall and disappear when he will move away. For example: I have small town with a few buildings and during the navigation when player will come closer to precise building the info box will appear (which will present info about that building: photos, text and etc.) and when he moves away from the building then info box will disappears. I am kind of new with unity, so I would be glad if somebody can explain me the code which I should use. Thank you ;-)
Dzioniux
Answer by melatonin · Feb 23, 2012 at 11:18 PM
The code he wrote has an error. The if statements should read:
if (theCollider.gameObject.tag == "Player")
He never defined other so Unity has no idea what to do with it. Try this simple fix and you should be good.
Answer by fireomega · Feb 22, 2012 at 08:38 PM
one way is you could have two scripts such as the one for the gui which you attach to an empty gameObject. I'm assuming you know how to make a gui box already. Name the object e.g. Info
Then make a empty gameObject at the building and attach a collider and make it a trigger. Then write something like:
var info : GameObject;
function Start () {
info.active = false;
}
function OnTriggerEnter(theCollider : Collider){
if(other.gameObject.tag == "Player"){
info.active = true;
}}
function OnTriggerExit(theCollider : Collider){
if(other.gameObject.tag == "Player"){
info.active = false
}}
haven't tested it yet, if there are any problems please ask.
Hi,
First of all, thank you for your answer ;-). I done all steps as you wrote, but I got an error: Assets/collision_info.js(9,4): BCE0005: $$anonymous$$ identifier: 'other'. Should I somehow define 'other' and my question about "gameObject.tag == "Player" " this means that it will use fps pref. which tag is Player, yes?
Best
Dzioniux
There is a simple error in the code. The if statement should read like this:
if ( theCollider.gameObject.tag == Player")
He is using other and since that hasn't been defined Unity doesn't know what to do with it.
Your answer
Follow this Question
Related Questions
script to create gui when detection collision between cube and first controler person ?? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Space ship UI, multiple pointer that follow individual targets. 1 Answer
Counting with GUI Textures 1 Answer
Gui Texture Swap? 1 Answer