helo guys, i’m trying to make the ghost wonder around the navigation without using waypoints but so far just manage to make de enemy ghost follow the player with the script
NavMeshAgent nav;
nav.SetDestination(player.position);
my idea is to make the ghost chase the player only if they are in range and only then use the script nav.SetDestination(player.position);
using UnityEngine;
using System.Collections;
publicclassEnemyAttack : MonoBehaviour
{
publicint attackDamage =100;
publicTransform player;
publicbool playerInRange;
PlayerHealth playerHealth;
// Use this for initialization
void Awake ()
{
player =GameObject.FindGameObjectWithTag("Player").transform;
playerHealth = player.GetComponent<PlayerHealth>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag =="Player")
{
playerInRange =true;
Debug.Log(playerInRange);
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag =="Player")
{
playerInRange =false;
Debug.Log(playerInRange);
}
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name =="Player")
{
Attack();
}
}
void Attack()
{
if (playerHealth.currentHealth >0)
{
playerHealth.TakeDamage(attackDamage);
}
}
}