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 FBX?

How to Adjust Unity Screen Rotation Settings?

Unity Visual Studio Debug Problem

What is Unity Asset Store?

What is Unity Header and Space Feature?