Hi,
I have a c# code below, it moves a object to another point. But I want to begin this code after mouse click. How?
void Update () {
// calculate current time within our lerping time range
float cTime = Time.time * 0.9f;
// calculate straight-line lerp position:
currentPos = Vector3.Lerp(startPos, endPos, cTime);
// add a value to Y, using Sine to give a curved trajectory in the Y direction
currentPos.y += trajectoryHeight * Mathf.Sin(Mathf.Clamp01(cTime) * Mathf.PI);
// finally assign the computed position to our gameObject:
transform.position = currentPos;
}
Just Add the input.GetMouseButtonDown(0) and a boolean to enter once in the condition.
Something like this.
private bool status = false;
void Update ()
{
if (input.GetMouseButtonDown(0) && status == false)
{
// calculate current time within our lerping time range
float cTime = Time.time * 0.9f;
// calculate straight-line lerp position:
currentPos = Vector3.Lerp(startPos, endPos, cTime);
// add a value to Y, using Sine to give a curved trajectory in the Y direction
currentPos.y += trajectoryHeight * Mathf.Sin(Mathf.Clamp01(cTime) * Mathf.PI);
// finally assign the computed position to our gameObject:
transform.position = currentPos;
status = true;
}
}`