hi, im quite new to unity and please forgive me if i wasted your time, but a piece of code of mine soft locks unity into an eternal state of loading every time i try to run my code, but there isnt any loops in the script that have on end. code attached below, thanks.
using System.Collections;
using System.Collections.Generic;
using Unity.AI.Navigation;
using UnityEngine;
using UnityEngine.AI;
public class EnemyLogic : MonoBehaviour
{
public GameObject Player;
NavMeshAgent agent;
public Transform[] waypoints;
void Start()
{
int childnum = 0;
agent = gameObject.GetComponent<NavMeshAgent>();
foreach (Transform child in GameObject.Find("Waypoints").transform)
{
childnum++;
}
waypoints = new Transform[childnum];
childnum = 0;
foreach (Transform child in GameObject.Find("Waypoints").transform)
{
waypoints[childnum] = child;
childnum++;
}
}
// Update is called once per frame
void Update()
{
Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, 25f, layerMask: LayerMask.NameToLayer("Player"));
if (colliders.Length > 1)
{
foreach (Collider collider in colliders)
{
agent.destination = Player.transform.position;
}
}
else
{
foreach (Transform waypoint in waypoints)
{
agent.destination = waypoint.position;
while (gameObject.transform.position != waypoint.position)
{
}
}
}
}
}