Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Child Number

Discussion in 'Scripting' started by Kellyrayj, Jul 1, 2016.

  1. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    933
    Hey friends,

    I'm searching for a way for a child object to know its order. So for instance, a game object has X number of children. I want the first child object to be able to tell me that it is the first in the list, the second to know that it is number 2 and so on.

    Any thoughts on how to achieve this?
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    iterating through the children with a for loop will tell you since the order is unlikely to change.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Kellyrayj and JamesLeeNZ like this.
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
  5. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    933
    Perfect! I was missing the right words to look up. Kept thinking, child... count... order... Thank you!
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    In fairness it's relatively new. Hasn't always been that easy.