- Home /
Checking duplicate position in a list
So I'm using a list to store the position of each object I have. I'm using contain to check if there are duplicate positions. My simple code works, however it doesn't change the position of the objects with same positions. Here's my code.
public List<Vector3> objPos = new List<Vector3>();
void Start () {
foreach (Transform child in ParentObj) {
objPos.Add (child.position);
child.position = new Vector3 (Random.Range (-10, 10), Random.Range (-8, 8), 0);
while (objPos.Contains (child.position)) {
Debug.Log ("Duplicate");
child.position = new Vector3 (Random.Range (20, 40), Random.Range (9, 18), 0);
objPos.Add (child.position);
}
}
}
Comment
Answer by WainWork · Oct 24, 2017 at 08:04 AM
Why u add to list in while cycle? Maybe add after while?