When I run this script, unity freezes. Why? How to fix it?
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
public class WalkingBoss : MonoBehaviour
{
private GameObject playerOb2j = null;
private GameObject TXT = null;
float timeToWait = 0.09f;
// Start is called before the first frame update
void Start()
{
if (playerOb2j == null)
playerOb2j = GameObject.Find("Boss");
if (TXT == null)
TXT = GameObject.Find("Cam");
}
// Update is called once per frame
void Update()
{
timeToWait -= Time.deltaTime;
if (timeToWait <= 0)
{
float x = playerOb2j.transform.position.x;
float z = playerOb2j.transform.position.z;
float finalx = TXT.transform.position.x;
float finalz = TXT.transform.position.z;
while (x!=finalx & z!= finalz)
{
transform.position = new Vector3(x+1, 1, z+1);
}
timeToWait += 0.02f;
}
}
}