Arranging GameObjects by custom property

Hi everyone,

I don’t know if this is a tricky one, or the answer is right in front of my face and I just can’t see it.

Let’s say that I have several GameObjects “cards” attached to a parent object (let’s call it “hand”). They all have attached a class that gave them a property.

public enum CardType {A, B, X, Y, wildCard}

When the cards are randomly instantiated they automatically get parented with the hand. But they get attached in the order they were created. How could I make them get arranged in a way that they get grouped by CardType.

Does anyone know?

Thanks in advance!

You may use this method:

If you want only to sort into 4 groups you may do something like this assuming that you will not have more than 100 objects of one type:

if(yourObject.type == 'A'){
elseif(yourObject.type == 'B') {

You may also create array which would transform your type into index for simpler assiging siblingIndex but above should be enough.