So I have a player that uses a line renderer animation to help with the trajectory.
The line render animates from one point to another using two game object positions.
The animation works perfectly the first time, however when re clicked the line renderer animation doesn’t reset. It just stays at full length.
Any ideas on how to reset the position so the animation starts every time the mouse is clicked?
Any help would be greatly appreciated
LineRenderer link;
public Transform[] pos;
public float speed;
bool assist;
public void Update()
{
if (Input.GetMouseButton (0))
{
StartCoroutine(Assist());
assist = true;
}
if (Input.GetMouseButtonUp (0))
{
StartCoroutine(Assist());
assist = false;
}
}
public IEnumerator Assist()
{
link = gameObject.GetComponent<LineRenderer> ();
if (assist == true)
{
yield return null;
link.enabled = true;
link.SetPosition(0, pos[0].position);
link.SetPosition(1, Vector3.MoveTowards (transform.position,pos[1].position,speed *Time.time));
}
if (assist == false)
{
yield return null;
link.enabled = false;
}
}
}