How to bring one child in front of another?

I have a GameObject plane prefab which is a parent of another GameObject plane.

So I’ve got this prefab:

  • parent

    1st child

In runtime, I add another child, so I’ve got

  • parent

    1st child
    2nd child

By default, the 2nd child shows up behind the 1st child (see picture: http://img145.imageshack.us/img145/2534/problemn.png). What I want is to bring it in front of it and so far I haven’t succseeded. Changing the index or the Z-position of either of both children does no effect, it is stuck in the parent’s Z-coordinates.

So what do I do?

You can set the position of an object relative to its parent using transform.localPosition. Note that you should change the Y coordinate of the child plane in this case.

Yes, setting transform.localPosition is exactly what I had been doing all along, but no result. But why change the Y coordinate? I don’t want any coordinates to change, I want them to stay where they are.

I solved the case by making the prefab completely empty and instantiating both children in the code. The child that is being added first stays in the front, and the other one goes behind. Not an elegant solution at all, but that’s the only one I could come up with. :confused: Now another problem has came up, I’ll add another thread about it.