How to determine active child and get data in NGUI

295 Views Asked by At

I ma trying to create an "SELECT" like wheel in my game with NGUI. I am doing so by creating a panel with a "center to child" attached to my scrollview. So far so good :-)

Now, I can't figure out how to determine which listitem (gameobject) is actual active?

Hoping for help in this matter and by the way. Merry Christmas :-)

1

There are 1 best solutions below

0
On

You are probably looking for gameObject.activeSelf, (a comment mentioned obj.active which is deprecated).

So iterate through your listitems something like:

foreach (var item in listitems) // this is pseudocode, not sure of the actual types
{
    if (item.gameObject.activeSelf){
        // Congrats you have your active item
    }
    // the item is not active
}

item in this context is the actual NGUI component that you are referencing, in Unity everything has a recursive lookup to it's parent game object, and it's parent's parent game object and so on. You can literally have a label on a nested game object and get down to the root by doing something silly like label.gameObject.gameObject.gameObject etc...

If you are just referencing the game object itself or a list of game objects, then just omit the item in my code.