Hello everybody,
I have a problem in Unity.
I follow the tuto with zombunnies on how to manager enemies.
I do almost the same scripts on enemies. The 1rst zombie appear normally (picture 1). But after 3sc when another wants appear, the zombies go through the scene and go in the corners on my terrain, always animated but not moving (see picture 2).
I don’t know why and how it’s possible ![]()
My codes are below:
public class walk : MonoBehaviour {
Transform player; // Reference to the player's position.
NavMeshAgent nav; // Reference to the nav mesh agent.
// Use this for initialization
void Awake() {
player = GameObject.FindGameObjectWithTag("Player").transform;
nav = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update() {
nav.SetDestination(player.position);
}
}
public class EnemyManager : MonoBehaviour
{
public GameObject enemy; // The enemy prefab to be spawned.
public float spawnTime = 3f; // How long between each spawn.
public Transform[] spawnPoints; // An array of the spawn points this enemy can spawn from.
void Start()
{
// Call the Spawn function after a delay of the spawnTime and then continue to call after the same amount of time.
InvokeRepeating("Spawn", spawnTime, spawnTime);
}
void Spawn()
{
// Find a random index between zero and one less than the number of spawn points.
int spawnPointIndex = Random.Range(0, spawnPoints.Length);
// Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation.
Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
}
}
