# [TowerDefense] How to show turrets range in game?

Updated 6 days ago in
6 on May 8, 2017

Hello!

I have a problem right now..

I finish the Tower Defense Course and i want more, so i decided to continue on my own since there’s no more videos on this. But i’m really new to unity and scripting, so forgive me if its in fact a simple thing to do.

And a thing that i really want is show the towers range to the player, so he can see it in the game and i don’t know how to do it in the script..

I read that apparently the “OnDrawsGuizmoSelected” can only be display in the editor..
So my idea was to create a cylinder with size on y axis about 0.0001, with a color and the alpha down, but i want to make it interractive with the range of different turret, so this cylinder can take the size of the current range selected.

Someone have an idea? I took any suggestion thanx you ðŸ˜€

• Liked by
on May 9, 2017
You could store the towersÂ pos as a vector 3 called “towerPos” and the players pos as a vector 3 called “playerPos” and then use Pythagoras Thereom to find the direct distance e.g.
float directDistance = Square Root( playerPos^2 + towerPos^2)

then you could just display this, I believe this should work!
Good Luck

on May 9, 2017

Okay i will try that, thanx for the suggestion ðŸ˜€

• Liked by
on May 10, 2017

If you can’t solve it with the first suggestion, which is basically using a circle equation you can draw a line by using the line renderer and creating points around the turret position.These points you can get by using Math.Sin() and Math.Cos().

This is the mathematical equation:

You need to decide how many points you want to draw and divide 2pi by that number to get “rad”. I have also seen Math.Deg2Rad () somewhere online, but I have never used that myself.

on May 14, 2017

Okay, it looks both a little complicated, but i will try it thanx for the suggestion guy ðŸ˜€

on May 17, 2017

Actually it isn’t really. Maybe I just explained it badly. If so I am sorry.

6 days ago

I know this is a bit old, but what about having a circle sprite that always faces the camera. Â It would be a .png file to preserve transparency and then you can easily customize and iterate the look of it in Photoshop. Â Then all you have to do is code the sprite to turn on when you need it and turn off when you don’t.

Any thoughts on this? Â Am I over-complicating it?