How to run a lerp with a left click ?

Hello all,

When i add a Input.GetMouseButtonDown my lerp do nothing ease, i don’t understand that :confused: i want inevitably mouse clic left for use this, please help me :frowning:

using UnityEngine;
using System.Collections;

public class controllermenu : MonoBehaviour {

	public Transform startMarker;

	public float speed = 1.0F;

	private float startTime;

	private float journeyLenght;

	public Transform target;

	public float smooth = 5.0F;

	void Start() 
	{
		if(Input.GetMouseButtonDown(0))
		{
		startTime = Time.time;
		journeyLenght = Vector3.Distance (startMarker.position, new Vector3 (-0.3F, 0, 1));
		}
	}

	void Update() 
	{
		if(Input.GetMouseButtonDown(0))
		{
		float distCovered = (Time.time - startTime) * speed;
		float fracJourney = distCovered / journeyLenght;
		transform.position = Vector3.Lerp (startMarker.position, new Vector3 (-0.3F, 0, 1), fracJourney);
		}
	}
}

You probably want

Input.GetMouseButton() 

instead of “GetMouseButtonDown”

I think this is the functionality you’re looking for. I added a boolean called “mouseClicked”. You can always change the name. And you might want to store “new Vector3 (-0.3F, 0, 1)” in a variable since it’s used twice. I figured I’d leave the variable naming to you.

using UnityEngine;
using System.Collections;
 
public class controllermenu : MonoBehaviour {

    public Transform startMarker;
 
    public float speed = 1.0F;

    private bool mouseClicked = false;

    private float startTime;
 
    private float journeyLenght;
 
    public Transform target;
 
    public float smooth = 5.0F;
 
    void Start() 
    {
        if(Input.GetMouseButtonDown(0))
        {
        startTime = Time.time;
        journeyLenght = Vector3.Distance (startMarker.position, new Vector3 (-0.3F, 0, 1));
        }
    }
 
    void Update() 
    {
        if(Input.GetMouseButtonDown(0))
        {
        mouseClicked = true;
        transform.position = startMarker.position;
        }

        if ( mouseClicked ) 
        {
        float distCovered = (Time.time - startTime) * speed;
        float fracJourney = distCovered / journeyLenght;
        transform.position = Vector3.Lerp (transform.position, new Vector3 (-0.3F, 0, 1), fracJourney);
        if ( Vector3.Distance(transform.position, new Vector3 (-0.3F, 0, 1) < .001F)
            mouseClicked = false;
        }
    }
}