How to stop Translate when I need?
<p>I have a cupboard with boxes. When I look on the box and press mouse button, I want to open/close it with <strong>Translate</strong>. I want to move box, till it's <strong>X</strong> coordinate will be 1.0 (and start point is 1.345). But it moves longer than that point.</p>

<p><a href="https://i.stack.imgur.com/EjhGj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EjhGj.jpg" alt="enter image description here"></a></p>

<p>I tried to use FixedUpdate, but it doesn't helped..</p>

<pre><code>public LayerMask mask;

private bool shouldClose;
private bool changeXCoordinate;
private Transform objectToMove;

void Update ()
{
    if (changeXCoordinate)
        OpenCloseBox();
    else if(DoPlayerLookAtCupboardBox() &amp;&amp; Input.GetMouseButtonDown(0))
        changeXCoordinate = true;
}

bool DoPlayerLookAtCupboardBox()
{
    RaycastHit _hit;
    Ray _ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
    bool isHit = Physics.Raycast(_ray, out _hit, 1.5f, mask.value);

    if (isHit &amp;&amp; !changeXCoordinate)
    {
        objectToMove = _hit.transform;
        return true;
    }
    else
        return false;
}

void OpenCloseBox()
{
    if (shouldClose)
    {         
        if(objectToMove.position.x != 1.345f) // It must stop at this point, but it don't
        {
            changeXCoordinate = false;
            shouldClose = !shouldClose;
        }
        else
            objectToMove.Translate(Vector3.right * Time.deltaTime);
    }
    else
    {
        if (objectToMove.position.x &gt;= 0.1f) // The same problem here..
        {
            changeXCoordinate = false;
            shouldClose = !shouldClose;
        }
        else
            objectToMove.Translate(Vector3.left * Time.deltaTime);            
    }
}
</code></pre>