multiple targeting

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

  1. set all your targets to the same tag

  2. get an array of all the targets with GameObject.FindObjectsWithTag()

  3. create an empty list of game objects; this one will store the targets you can shoot

  4. loop through all the objects in the array (See Example 2)

  5. for each target, find the vector between the game object and your character using vector substraction

  6. with this vector, find the square magnitude.

  7. use an if-statement to check if the square magnitude is less than range suared.

  8. If it is, that means that your target is within range, so you should add it to the list of targets you can shoot.

  9. when the loop is done, you should have all the targets that can be shot at within range.