Question by
Maleesha_Safdari · Oct 22, 2017 at 10:28 AM ·
unity 5scripting problemfighting
Why i cant create a slot for my player in enemymove script so enemy chase her?
I wanted to make a fighting game where the enemy chase the player and fight her but my code had slot for player but not now this is the error Assertion failed. Value was Null Expected: Value was not Null UnityEngine.Assertions.Assert:IsNotNull(Transform) EnemyMove:Awake() (at Assets/Scripts/EnemyMove.cs:16)
using UnityEngine; using System.Collections; using UnityEngine.Assertions; using UnityEngine.AI;
public class EnemyMove : MonoBehaviour {
private Transform player;
private NavMeshAgent nav;
private Animator anim;
private EnemyHealth enemyHealth;
void Awake() { Assert.IsNotNull(player); }
void Start()
{
player = GameManager.instance.Player.transform;
enemyHealth = GetComponent<EnemyHealth>();
anim = GetComponent<Animator>();
nav = GetComponent<NavMeshAgent>();
}
void Update()
{
if (!GameManager.instance.GameOver && enemyHealth.IsAlive)
{
nav.SetDestination(player.position);
}
else if ((!GameManager.instance.GameOver || GameManager.instance.GameOver) && !enemyHealth.IsAlive)
{
nav.enabled = false;
}
else
{
nav.enabled = false;
anim.Play("Idle");
}
}
}
Comment