Searching Multiple GameObjects By Unity Tag

In Unity, the FindGameObjectsWithTag() method is used to find all GameObject assigned to a Tag

The method returns an Array of GameObjects. If it can't find a result according to the specified Tag, it returns an empty array.

An example code is given below..

public class UnityTest : MonoBehaviour { public GameObject[] players; void Start() { players = GameObject.FindGameObjectsWithTag("Player"); } }

In the example, GameObject array named "players" has been created, all GameObjects with "Player" Tag are found by our method and assigned to this array.



You May Interest

Checking If Unity GameObject Has Child Object

What is Unity Asset?

Unity Main Camera Tracking Player

What is Unity StartCoroutine ?

What is Unity SiblingIndex ?