My unity freezes as i press the play button. The code is not in an infinite loop either. I’m just a beginner. Please help me out. As soon as i remove the code from the object it plays perfectly. When i apply it to the object it freezes when i press the play button.,Unity just freezes when I press the play button. Just a small code but i dont think there is an infinite loop.
This is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rock : MonoBehaviour {
[SerializeField] Vector3 topPosition;
[SerializeField] Vector3 bottomPosotion;
// Use this for initialization
void Start () {
StartCoroutine(move(bottomPosotion));
}
IEnumerator move(Vector3 target)
{
while (Mathf.Abs((target - transform.localPosition).y) > 0.20f) ;
{
Vector3 direction = target.y == topPosition.y ? Vector3.up : Vector3.down;
transform.localPosition += direction * 4 * Time.deltaTime;
yield return null;
}
print("Reached the Target");
yield return new WaitForSeconds(0.5f);
Vector3 newTarget = target.y == topPosition.y ? bottomPosotion : topPosition;
StartCoroutine(move(newTarget));
}
},