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

What is Unity Asset Store?

What is Unity Collider ?

What is Unity StartCoroutine ?

How to Adjust Unity Screen Rotation Settings?

What is Unity Asset?