- Home /
Creating and removing HUDs on Collision
I want to be able to create HUD's on a first person controller collision with objects for example when the user starts they have to find a list of things to fine, a list of those objects appear on the side as HUD's and when the user finds the item the HUD for that object is removed as it no longer needs to be found.
I also want a map hug to appear in a top corner.
I'm coding in Javascript if that helps :)
This is my first project with Unity3D ever, so any help would be awesome, thank you :)
one thing at a time... start with the script reference, it has all the answers:
http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html
http://docs.unity3d.com/Documentation/Components/gui-Basics.html
I don't understand how that helps, thats creating buttons when i went text, and none of them deal with appearing from a collision as far as i can see
I'm typing this with my phone so I can't give detailed answer, but try http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionEnter.html
I'm sorry but i don't understand how that helps either.
I have a ontrigger event for when a collision takes place and the item is removed, if that helps
Answer by Seth-Bergman · Mar 10, 2013 at 10:39 AM
http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html
http://docs.unity3d.com/Documentation/Components/gui-Basics.html
The first link has links to EVERY GUI control... not just buttons!!! take the time to READ IT, and you may BEGIN to understand
here's how to do what you ask...
(if this helps you, please be sure and click the check mark to accept my answer)
first, we can create a var to decide whether to show our HUD:
var showSampleHud : boolean = false;
a boolean is either true or false
now we can set up our GUI:
function OnGUI(){
if(showSampleHud){
GUI.Box(Rect...etc
GUI.Label(Rect(Screen.width...etc
GUI.SEE SCRIPTING GUIDE!!!...etc
}
}
now all that's left is the collision:
function OnCollisionEnter(other : Collider){
if(other.tag == "showme")
showSampleHud = true;
}
of course, your collision will require the proper setup to register, i.e. a collider or character controller on each object, and at least one rigidbody for starters..
Here's the whole script:
var showSampleHud : boolean = false;
function OnGUI(){
if(showSampleHud){
GUI.Box(Rect...etc
GUI.Label(Rect(Screen.width...etc
GUI.SEE SCRIPTING GUIDE!!!...etc
}
}
function OnCollisionEnter(other : Collider){
if(other.tag == "showme")
showSampleHud = true;
}
hope this helps!
I get a error saying "The name 'collider' does not denote a valid type'
oops it needs to be capital, i'll fix it..
fixed.. but keep in $$anonymous$$d collisions can be tricky..
of course, you also need to remember to make sure the tag is set up on your object
and do NOT set to isTrigger
and at least one of the objects needs a rigidbody (maybe both..)
the collision matrix at this link (near the bottom) can be helpful:
http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
The only problem is that it starts on and then on the collision goes off, i want it to start off, then come on, after a collision, but then again removed when it collides with the correct item
you should have no problem using this example to figure that out!
just switch "true" and "false" as needed!
for different reactions, use different tags!
if(other.tag == "showme")
showHUD = true;
if(other.tag == "target")
showHUD = false;
if this is too much to grasp, you should take a step back and learn the basics of program$$anonymous$$g FIRST, me writing your game for you doesn't help you!
switching true and false on that is making no difference at all.
I can do program$$anonymous$$g, i can do flash, i'm just struggling to get this, seems overly complex when it doesn't need to be.
Your answer
Follow this Question
Related Questions
How to move an object over a distance in a direction? 2 Answers
How to approximate this surface with primitives? 1 Answer
Pickaxe Collision Problems 1 Answer
My weapon takes damage. help... 1 Answer
How to get A Camera Collision? 1 Answer