Skip to content

Common.Tag

DucNV_2000 edited this page Jul 10, 2024 · 1 revision

Common.Tag

  • FindComponentInChildWithTag Find component by tag
 T FindComponentInChildWithTag<T>(this GameObject parent, string tag)

Example

   public GameObject player;
   private BoxCollider _boxCollider;

   public void GetBoxColliderPlayer()
   {
       _boxCollider = player.FindComponentInChildWithTag<BoxCollider>("Player");
   }
  • SetLayer Set layer for this game object
 GameObject SetLayer(this GameObject obj, int layerIndex)
  • SetLayerForAllChildObject Set layer for this game object and all child of game object
 GameObject SetLayerForAllChildObject(this GameObject obj, int layerIndex)

Example

    public GameObject player;
    public void SetLayerForAllChildPlayer()
    {
        player.SetLayerForAllChildObject(LayerMask.NameToLayer("Layer_Player"));
    }
  • SetTag Set tag for this game object
 GameObject SetTag(this GameObject obj, string tag)
  • SetTagForAllChildObject Set tag for this game object and all child of game object
 GameObject SetTagForAllChildObject(this GameObject obj, string tag)

Example

    public GameObject player;
    public void SetTagForAllChildPlayer()
    {
        player.SetTagForAllChildObject("Tag_Player");
    }
Clone this wiki locally