How can i make my object stop


I have two objects as squares. I also have 2 planes in those boxes… I can select those boxes. When i select those boxes i add them to a list and if there are 2 items in the list a button appears… If player press this button my game object (one of them) should move to the direction of to other and should stop when it can it collide with it…

I used a code which i gave the second object coordinates. I cannot make my object stop when it collide instead it stop when it reaches to the coordinate… Here is some coding:

GameObject object1 = GameObject.Find ("Cube 000");
Unit unit = object1.GetComponent<Unit>();
while(unit.flag2 == false)
    arrayObject [0].position = Vector3.MoveTowards (arrayObject [0].position, lastP.transform.position, moveSpeed * Time.deltaTime);

This is in a script called snap. So its not in the main object script… Thats why i get the info like that… And in the script for each pieces that i have in game here is the script:

void OnCollisionEnter(Collision other)
if ( == "Cube 000") 
	flag2= true;
	print (flag2.ToString());

So this code works to make my pieces go towards to other it hits it (which alson cause a rotation when it hits and i couldnt solve that yet) and continues to push until it reaches to the right coordinate…

Any suggestions?
alt text

why do you have that break; in the while loop? that seems unneccessary and may be part of the problem. Also, to fix your collision rotation problem, dont use OnCollisionEnter use OnTriggerEnter(one of the objects will need to have IsTrigger checked on the collider component).