Can't Figure out how to go about creating this part.

So, its a tank simulation. User may press “Space” to fire missile from cannon. Okay that is fine. But what is a tank with only 1 cannon? This big guy has rocket launchers, machine guns, lasers, good stuff. the machine gun and lasers and cannon i know. But the rocket launcher system is slightly mind blocking me. I have the rocket programmed to fly up 30 yards, rotate, and blast towards the target. works great. Problem is selecting the target(s). I would like to have the set up to where when you press the “T” key, the rocket launcher throws a GUI, or some sort of visual sign/icon(Over anything in the way, hills, walls, w.e. is blocking the view from the player to the target, but showing over all possible targets in scene then can press “G” to tab through the targets, then press “Enter” to fire the rocket(Setting the rockets target to the selected target). I’ve been thinking for a few hours now on how to go about this but comming up with nothing.

Questions:

  1. How to scan for every enemy tank in the scene.
  2. How to tab between those targets.
  3. (Most important) How to display a visual such as GUI, Icon, 2DTexture, Light, something like that, on the targets, making the currently selected have a different visual to show they are the current target.

Example image below.

Any advice?

Feel free to not laugh at my artistic paint ablity.

You can do a raycast to find out the targets you can see…

To find all possible targets you could do:

var enemies : GameObject[];

function Update()
{
enemies = GameObject.FindGameObjectsWithTag("Enemy");
}

Note: You don’t have to do it in the update, you could make it more like a scan with InvokeRepeating and move it into a seperate function. Or do it in Start() if all your tanks exist from the very beginning.

As far as tabbing between targets and visually representing the selected target, I’d suggest you google “Bergzerg Hack & Slash”. I don’t remember which video exactly, but he does a 270+ rpg video tutorial and in the first 5-6 videos of the tutorial he covers your 2&3rd question in a video labeled “Targetting” or something like that.

Edit: sorry I was incorrect, it actually starts here–

  1. You can tag enemy tanks with a specific tag, e.g. Enemy (easiest way is to just set this tag on a prefab). When you scan, use FindGameObjectsWithTag to find all of them. . Assign return value to targets array.

  2. Create a new variable selectedTargetIndex (int), initially set to zero. When you press Tab, increment it, when Shift+Tab, decrement. If, after increment, it is equal to a number of elements of targets array, set it to zero. If, after decrement, it is lower that 0, set it to number of elements minus 1. This index will allow you to get current enemy tank from your array.

  3. You can use GUI.DrawBox, GUI.DrawTexture or any other GUI method. To get proper coordinates, you need to call Camera.WorldToScreenPoint, passing currently selected transform position, e.g.

    Camera.main.WorldToScreenPoint(targets[selectedTargetIndex])

You will probably need to add some offset, but this should be fairly easy.

Another way to highlight, is to change shader on your selected object. You can for example make it red tinted and slowly blinking.