Search Unity

How to access Child game object through tag?

Discussion in 'AR/VR (XR) Discussion' started by saifshk17, Apr 5, 2018.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    259
    Hello all,

    I have a child game object with tag "Player1" and a parent game object with tag "Players". Below is my script where I am trying to access the child object but it doesn't happen. "objectPlayer is the Parent gameobject which contains children (Player 1-3). What am i doing wrong?

    Thank you.

    Code (CSharp):
    1. IEnumerator Disappear()
    2.     {
    3.      
    4.            
    5.             for (int k = 0; k < objectPlayer.Length; k++)
    6.         {
    7.          
    8.                 if (objectPlayer[k].tag == "Player1")
    9.                 {
    10.                     yield return new WaitForSeconds(1);
    11.                     objectPlayer[k].SetActive(false);
    12.                 }
    13.             }
    14.            
    15.        
    16.     }
     
  2. TeemuMV

    TeemuMV

    Joined:
    Nov 10, 2017
    Posts:
    19
    Not remotely relevant to XR.

    GOs don't have .Length., are you looking for .childCount?
     
unityunity