Please help me good sirs/ma'ams!

So I’m making a rather simple 2D game with boxes falling down in ‘spawnWaves’ and my only problem is that I wanted to change the velocity/direction of the one with the lowest y-axis value depending on the user’s input (whether left or right arrow key)… Obviously, the reason why I’m here is that I can’t.

I can change the velocity/direction no problem but once I do… all of them (the boxes) move at once and that’s not what I want. I only want to access the one with the lowest y-axis value.

That’s all. If someone actually reads this and maybe have some suggestion, I would deeply appreciate it. I aspire to create my own video game company someday and I’m not gonna give up.

Thanks everyone! :>


If I understand you correctly:

GameObject obj; // add a parent object to your boxes
GameObject theLowest = null;
for (int i = 0; i<obj.GetComponent<Transform>().childCount; i++)
    if (theLowest == null || 
        theLowest = obj.GetComponent<Transform>().GetChild(i).gameObject;