- Home /
Question by
Himani_123 · May 26, 2014 at 12:06 PM ·
javascript
Sorting an array of clones by their position and compare them
how to compare the positions of the clones of two array list..??i tried this snippet but it didn't work for me.gems is the arraylist in which positions of clones get shuffle and gems1 donot get shuffle only instantiate with the gems in the starting before shuffling the positions of the clones in the gems list.
public List<Gem> gems = new List<Gem>();
public List<Gem> gems1 = new List<Gem>();
public void WinOrLose( )
{
gems1 = gems.OrderBy(ge => ge.transform.position.x);
for(int i=0;i<gems.Count;i++){
//for(int j=0;j<gems1.Count;j++){
if (gems[i].transform.position!=gems1[i].transform.position)
{
print (gems[i].transform.position);
print (gems1[i].transform.position);
}
else{
print ("matched");
}
}//}
}
Comment
Answer by Asteiros · May 26, 2014 at 12:31 PM
Try to compare positions x,y properties.Some thing like that:
if (gems[i].transform.position.x!=gems1[i].transform.position.x
||gems[i].transform.position.y!=gems1[i].transform.position.y)
{
print (gems[i].transform.position);
print (gems1[i].transform.position);
}
else{
print ("matched");
}
@ Asteiros it return true. on calling this function onstart(). i want to ask if it is returnign true that means positions of gameobject is not shuffle.,but on start() it get shuffle with snippet.
for(int i = 0; i < gems.Count; i++) {
Vector3 temp = gems[i].transform.position;
randomIndex = Random.Range(0, gems.Count);
gems[i].transform.position = gems[randomIndex].transform.position;
gems[randomIndex].transform.position = temp;
then why it retuning true..please help me in this.