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);
}
}