My code crashes whenever I click…
void Update ()
{
if (Input.GetMouseButtonDown (0) == true)
{
StartCoroutine(OnLClick());
}
}
IEnumerator OnLClick ()
{
yield return new WaitForSeconds(.01f);
Vector3 stwpCamera = Camera.main.ScreenToWorldPoint (Input.mousePosition);
while (!(transform.position == stwpCamera))
{
transform.position = Vector3.Lerp (transform.position, new Vector3(stwpCamera.x, stwpCamera.y, -10), Time.deltaTime);
}
}
Any help would be greatly appreciated.