For Loop Problem

Hey guys, I think my problem is very easy but I’m dumb.

I need to make pick up script but now when I try to pick up something only name0 is active.

for (int i = 0; i < sticksMan.sticks.Length; i++)
        {
            GameObject foundStick = sticksMan.transform.FindChild(name + i).gameObject;

            if (foundStick.activeInHierarchy == true)
            {
                     //???
            }
            else if (foundStick.activeInHierarchy == false)
            {
                foundStick.SetActive(true);
                Destroy(gameObject);
                foundStick = sticksMan.transform.FindChild(name + i).gameObject;
            }
            break;
        }

Hope you guys help!

Is your object named as follows? “ITEM 0” or “ITEM0”. transform.FindChild(name + i) will look for an object like “ITEM0”. If you want “ITEM 0” you need transform.FindChild(name + “” + i)

When you call Destroy(gameObject); you’re destroying the GameObject the script is attached to which might be why the rest of the script isn’t run.

Actually solved this.