- Home /
Spotting Enemies Like In Battlefield 3?
How do I make a tagging system where if the player pressed a button on an enemy, there would be a tag above his head that follows him? It should also show through walls and objects. How do I do something like this? Thanks
Answer by D4rt · Jul 05, 2013 at 01:11 AM
A big question, but I think I have the necessary components for you to get started.
1. Detect the mouse/button click on the object.
This is the easiest way for mouse clicks: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnMouseDown.html
If you need it to be a keyboard button, you should use raycasting: http://docs.unity3d.com/Documentation/ScriptReference/Collider.Raycast.html http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
2. Create a floating tag
This is for displaying text in 3D space for the actual tag:
http://docs.unity3d.com/Documentation/Components/class-TextMesh.html
If the tag is only an image then you can just create a plane and add the texture to that.
You'd have to come up with a way to rotate the tag towards the camera (easiest way is to just copy the cameras rotation). Then just position it above the target players head (parenting is a good trick here). http://docs.unity3d.com/Documentation/ScriptReference/Transform-parent.html
3. Make the tag visible through other objects.
You'll need a new camera. Create a new layer and call it something like "Tag". Set the culling mask of the new camera only to "Tag". Set the layer of the actual tag to "Tag" as well. Parent the new camera to your main camera and make sure the position and rotation of the new camera are zero. Vóila.
EDIT: Couple things forgotten. The "Depth" of the new camera must be bigger than the "Depth" of the main camera. Also the "Clear Flags" of the new camera must be set to "Depth only".
I wonder who down voted me. ... any ways, thanks for this answer
The tag is not going through objects. I did everything you said to do. What's wrong?
Hard to say. Have you tinkered with the camera depth? The tag cameras depth should be bigger than the main cameras
EDIT: If you give more information, for example what works and what doesn't and maybe a picture of your setup I could perhaps help more.
I have tried adjusting the depth but when I do, I can't see anything anymore, just the skybox
Your answer
Follow this Question
Related Questions
Creating a particle system that uses 1 draw call 0 Answers
How to create a tag like system. 1 Answer
is it possible to have two different passes in Shader 0 Answers
How can I make fatal particles? (C#) 1 Answer
Accessing local system ( File Browser ) 2 Answers