Search Unity

How to check ChildrenTag if parent TAG don't have a ChildrenTag?

Discussion in 'Scripting' started by Slyrfecso1, Nov 30, 2015.

  1. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    Hi,

    I'd like to know if "go.name" don't have named children tag, then I do something.

    Code (CSharp):
    1. GameObject[] objectsPrice = GameObject.FindGameObjectsWithTag("Player");
    2. foreach (GameObject go in objectsPrice)
    3. {
    4. ...
    5. }
    6.  
    7. Renderer[] rendererComponents = go.GetComponentsInChildren<Renderer>();
    8. foreach (Renderer component in rendererComponents)
    9. {
    10. ...
    11. }
     
    Last edited: Nov 30, 2015
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    The .tag field is just a string. You can compare two GameObjects tag fields to see if they have the same string tag.

    If you mean does something have a script/component, then you can do a .GetComponent<>() call on it and see if you get a non-null reference.