GameObject Search By Unity Tag

In Unity, the FindWithTag() method is used to search for a GameObject by the Tag assigned to it.

Note : Only 1 "Tag" can be assigned to GameObjects.

An example of its use is given below.

public class UnityTest : MonoBehaviour { public GameObject player; void Start() { player = GameObject.FindWithTag("Player"); } }

In the example we found a "GameObject" with the "Tag" in the name "Player" and assigned it to the variable "player".

If there is more than one GameObject assigned to the corresponding Tag, the "FindWithTag()" method returns the first GameObject it finds. Therefore, when using this method, it should be noted that Tag is assigned to only 1 GameObject.



You May Interest

Running Your Unity Project From Any Visual Studio You Want

How to Adjust Unity Screen Rotation Settings?

How to Install Unity UI Toolkit Package ?

What is Unity Collider ?

Finding Unity SDK Path