Hi, I was writing an Enemy AI code using a tutorial (ENEMY AI - Making an RPG in Unity (E10) - YouTube). I am running into this error and I am unable to understand how to fix it. I am pretty new in C#.
(Enemy Controller Code)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyController : MonoBehaviour
{
public float lookRadius =90f;
Transform target;
NavMeshAgent agent;
void Start()
{
target = PlayerManager.instance.player.transform;
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
float distance = Vector3.Distance(target.position, transform.position);
if (distance <= lookRadius)
{
agent.SetDestination(target.position);
}
}
void OnDrawGizmosSelected(){
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, lookRadius);
}
}
(Player Manager)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerManager : MonoBehaviour {
#region Singleton
public static PlayerManager instance;
void Awake ()
{
instance = this;
}
#endregion
public GameObject player;
public void KillPlayer ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}