I’m making an FPS and I’m making the enemies move to rando set logations around the map but for some reason they aren’t moving
here’s the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class enemyNavigation : MonoBehaviour
{
protected NavMeshAgent Agent;
protected StateEnum State;
protected Target[] PotentialTargets;
protected Target target;
protected float NextState;
// Start is called before the first frame update
void Start()
{
Agent = GetComponent<NavMeshAgent>();
PotentialTargets = FindObjectsOfType<Target>();
target = PotentialTargets[Random.Range(0, PotentialTargets.Length)];
State = StateEnum.Run;
}
// Update is called once per frame
void Update()
{
Agent.updatePosition = false;
Agent.updateRotation = false;
Agent.updateUpAxis = false;
NextState -= Time.deltaTime;
switch (State)
{
case StateEnum.Run:
if(Agent.desiredVelocity.magnitude < 0.1f)
{
State = StateEnum.Shoot;
NextState = Random.Range(1, 7);
}
break;
case StateEnum.Shoot:
if(NextState < 0)
{
State = StateEnum.Run;
target = PotentialTargets[Random.Range(0, PotentialTargets.Length)];
Agent.SetDestination(target.transform.position);
}
break;
}
transform.position += Agent.desiredVelocity * Time.deltaTime;
}
public enum StateEnum
{
Run,
Shoot
}
}
if you need anything else just ask.