lerp position with mouseclick on object?

Hi guys i got this code from a tutorial video. But i want to click on a object and it moves in position B when i click again on the object it should move back to position A. I read that a bool is used for this but i dont understand it. Can someone ad a few lines code for this. Im pretty new to scripting.

using UnityEngine;
using System.Collections;

public class lerp : MonoBehaviour
{
    private Vector3 newPosition;

    void Awake ()
    {
        newPosition = transform.position;
    }

    void Update ()
    {
        PositionChanging ();
    }

    void PositionChanging ()
    {
        Vector3 positionA = new Vector3(-15042,30,23148);
        Vector3 positionB = new Vector3(-15042,40,23148);

        if (Input.GetKeyDown (KeyCode.Q))
            newPosition = positionA;
        if (Input.GetKeyDown (KeyCode.E))
            newPosition = positionB;

        transform.position = Vector3.Lerp (transform.position, newPosition, Time.deltaTime);
    }

}

Here you go. If you want to have the object stationary until you click it the first time, you’ll need to change the bool to an int and use different int values to represent which destination to move towards (ie. 0 = stationary, 1 = position A, 2 = position B). Good luck!

2162496–142933–lerp.cs (1.41 KB)

This is awsome. Thank you very much. It worked perfect. Im really happy right now :smile: