Question by
vithorescames · Dec 15, 2016 at 04:33 PM ·
arraynavmeshnullreferenceexceptionnavmeshagentwarp
NavMeshAgent Warp error
Hello guys, I'm trying to reset enemys' position when player press the "return" button when he dies, but because of NavMeshAgent they are not teleporting correctly to their initial positions. Then I'm using Warp, but I'm getting null reference error. Can someone explain why I'm getting this error or suggest an alternative?
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
public class Respawn : MonoBehaviour {
public Vector3 ultimoCheck;
private GameObject morte;
private GameObject pause;
//private GameObject[] inimigos;
private enemyPatrol scriptInimigos;
private GameObject puzzle;
private GameObject[] arrayInimigos;
private Vector3[] posInicial;
private NavMeshAgent[] navComp;
// Use this for initialization
void Start () {
morte = GameObject.FindGameObjectWithTag ("morte");
pause = GameObject.Find ("Pausa");
//inimigos = GameObject.FindGameObjectsWithTag ("Inimigo");
puzzle = GameObject.Find ("Puzzle");
ultimoCheck = transform.position;
arrayInimigos = GameObject.FindGameObjectsWithTag ("Inimigo");
posInicial = new Vector3[arrayInimigos.Length];
navComp = new NavMeshAgent [arrayInimigos.Length];
for (int i = 0; i < arrayInimigos.Length; i++) {
posInicial [i] = arrayInimigos [i].transform.position;
}
}
// Update is called once per frame
void Update () {
}
public void ispauma(){
morte.GetComponent<Canvas> ().enabled = false;
// GetComponent<FirstPersonController> ().enabled = true;
pause.SetActive (true);
puzzle.SetActive (true);
transform.position = ultimoCheck;
for (int i = 0; i < arrayInimigos.Length; i++) {
arrayInimigos [i].transform.position = posInicial [i];
navComp[i].Warp (posInicial [i]);
//navComp [i]. = arrayInimigos [i].GetComponent<NavMeshAgent> ().enabled = true;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How do I call Nav Mesh agent Stop 1 Answer
NavMesh Agent doesn't work with slope 0 Answers
Navmesh baking unwalkable paths that don't make sense to me 0 Answers
How to add a directional constraint on a NavMesh ? 0 Answers
What does desiredVelocity do? 0 Answers