0
I’m making this mistake:
Nullreferenceexception: Object Reference not set to an instance of an Object Enemymovement.Awake () (at Assets/Scripts/Enemy/Enemymovement.Cs:13)
Code:
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour
{
Transform player;
NavMeshAgent nav;
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
nav = GetComponent <NavMeshAgent> ();
}
void Update ()
{
//if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
//{
nav.SetDestination (player.position);
//}
//else
//{
// nav.enabled = false;
//}
}
}
Can you prove that the tag is exactly
Player
, and that it is already on the scene to be accessed by the method? Because there is nothing wrong with your code.– DH.
very good. thank you.
– Gean Carlos