- Home /
How to highlight certain gameObjects in an screenarea
I have a 3d scene with obstacles and enemies (tagged as enemy). I also have a round crosshair of a diameter of 100 pixels which represents the spread of my gun. The crosshair follows the mousecursor while the camera is fixed. What i now want, is to highlight (color) the crosshair area which overlap an enemy when the enemy is not occluded by other objects in the scene. What is the best approach?
Additionally it would be really nice to calculate the percentage of enemy-area under the crosshair (aka the hitchance)
Thanks for any advice
Lots of stuff to do.
You first need a shader that suit your needs, maybe a toon shader outline with a red color for the outline can be enough.
Then you need to raycast trough walls (layermasks can help) and when it hit enemy change his shader to the outlined with a coroutine inside the enemy script. The coroutine have to stop itself after a while and put the original shader when you are not calling it again (check with booleans if coroutine is running in order to not run it multiple times)
Edit: about the inocclusion thing you probably have to set the walls alpha you hit with a RaycastAll
Good luck!
Oh, i think i was a little misleading in the occluded explanation. Of course i only want to mark the areas of the enemy that are not occluded by other Objects. So i want to mark the parts of the enemy that can actually be seen.
Oh, then just change the enemy shader as I said. If the rest of the body is not to be seen who cares the shader it's having ;)
i do, because the cam im talking about is just the secondary "action cam" :)
i still dont understand your shader approach. Even if there where only one cam. Who gets the shader? The enemy or the Crosshair? And what kind of shader? Can you elaborate your answer a little more, please? :)
Your answer

Follow this Question
Related Questions
Issue with clicking with a crosshair while using Oculus Rift 1 Answer
My crosshair is moving the opposite of the mouse position. Why? 1 Answer
Getting Bounding box from a collider with children 1 Answer
Question about letting the user choose 2 buttons and highlight them 0 Answers
Keep gameobject highlighted until another gameobject is selected (multiple gameobjects) 2 Answers