how to loop the “var target : Transform;” my aim is to set a range for the target that when they reach the range, that object will become the target
-
set all your targets to the same tag
-
get an array of all the targets with GameObject.FindObjectsWithTag()
-
create an empty list of game objects; this one will store the targets you can shoot
-
for each target, find the vector between the game object and your character using vector substraction
-
with this vector, find the square magnitude.
-
use an if-statement to check if the square magnitude is less than range suared.
-
If it is, that means that your target is within range, so you should add it to the list of targets you can shoot.
-
when the loop is done, you should have all the targets that can be shot at within range.