Add Targeting Reticule
Now let’s add a targeting reticule that highlights the enemy targeted by our torpedoes:
Ok, were going to add a reticule sprite, then assign it to a child game object of the Enemy. Then we are going to add a script to the new game object that turns the Sprite Renderer on and off, and then call the script from our Laser when our torpedoes are active.
So, first the sprite. I found this very cool sprite sheet online:
So I added it to my Unity project, and sliced it up in the editor.
Next, we create a new game object, Reticule, and child it to our Enemy. Pick one of the sprites and add it to the Sprite Renderer of our Reticule. Resize it to fit, and make sure the Sprite Renderer is not active.
Now let’s add a new script, to our Reticule game object. We just need two new methods — Targeted() and unTargeted(). And those methods will enable and disable the <SpriteRenderer>:
Ok, now we just need to call our new methods. We will untarget them when we FindClosestEnemy() and target them when we TargetClosestEnemy():
And lastly, we need to make sure to untarget an enemy if our missile unintentionally collides with an untargeted enemy on it’s way to the target:
And that’s it. Now our player can see what enemy has been targeted. Surprisingly, I feel like in this game it’s actually more fun without the reticules. But it was still fun to make them. ;)