var PosList : List.<float>;
var ObjList : List.<GameObjects>;
I want to arrange the first list, and the second list to be arranged accordingly to the first one.
For example:
//list one contains:
[3]
[1]
[2]
//list two contains gameObjects with the names:
[number3]
[number1]
[number2]
//I sort the first list, so I use:
PosList.Sort();
//Now the first list became:
[1]
[2]
[3]
//How can I arrange the second list to mach the first one? //Like this:
[number1]
[number2]
[number3]
You should better use Dictionary<float, GameObject>. So once you call Sort, it will be sorted as per the key. Or you can try custom sorting procedures.
Using dictionary you don;t have to be precise about the value on each index, once the key sorted there corresponding value will be moved in the same way.
[Serializable]
public class PositionedGameObject
{
public GameObject gameObject;
public float gameObjectPosition;
}
// Later...
public List<PositionedGameObject> positionedGameObjects;
// Event later...
positionedGameObjects.Sort(ComparePositionedGameObjectByWhateves);
What you have: you store a list of multi-purpose “complex” objects (a game object and its associated position) in a distributed manner in two lists which causes desyncing on top of being very unintuitive.
What you actually want: create a class/struct that describes an object and its position together. Store a list of instances of that class/structure. Vuala, now try to have them unsynced. You can’t.