Question by
fametune · Jul 15, 2018 at 02:04 PM ·
c#programmingnavmeshagentspawning problemsenemy spawn
Can't spawn more than one NavMeshAgent wave system
Hey Guys, So I'm working on this wave beat em up / shoot em up. I have characters that are NavMeshAgents, and I have characters that are not. The enemywavesystem spawns the non-navmesh agents just flawless, and also spawn a navmesh one wthout a trouble. However if I have more than one navmesh agents in a wave, the other navmesh based ones doesn't appear, always just the first one. If I put multiple navmesh agents just on the level, so outside my spawn system, all of them work and move just fine. So I think it's not my spawn system that's actually wrong, I guess I messed up something with the script I put on all my navmesh agents, see it below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityStandardAssets.Characters.ThirdPerson;
public class navmeshTarget : MonoBehaviour
{
public Transform target;
private NavMeshAgent agent;
public ThirdPersonCharacter character;
public Animator animator;
// Use this for initialization
void Start()
{
agent = GetComponent<NavMeshAgent>();
animator = GetComponent<Animator>();
agent.updateRotation = false;
GameObject playa = GameObject.FindWithTag("Player");
target = playa.transform;
}
// Update is called once per frame
void Update()
{
agent.SetDestination(target.position);
if (agent.remainingDistance > agent.stoppingDistance)
{
character.Move(agent.desiredVelocity, false, false);
animator.SetFloat("Speed", 1);
}
else
{
character.Move(Vector3.zero, false, false);
animator.SetFloat("Speed", 0);
}
}
}
Comment