I watched 2 youtube videos…i will attach the codes here…but still none of them are working for me…(note- it is working for the youtubers) pls someone help as soon as possible asap…
script 1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyMovement2 : MonoBehaviour
{
UnityEngine.AI.NavMeshAgent nm;
public Transform target;
public enum AIState { idle,chasing};
public AIState aiState = AIState.idle;
void Start()
{
nm = GetComponent<UnityEngine.AI.NavMeshAgent>();
}
void Update()
{
}
IEnumerator Think()
{
while (true)
{
nm.SetDestination(target.position);
yield return new WaitForSeconds(1f);
}
}
}
script2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyMovement : MonoBehaviour
{
public float fov = 120f;
public Transform target;
public bool inSight;
public float AwakeDistance = 200f;
public bool AwareOFPlayer;
public NavMeshAgent enemyAgent;
private void update(){
float PlayerDistance = Vector3.Distance(target.position, transform.position);
Vector3 playerDirection = (target.position - transform.position);
float playerAngle = Vector3.Angle(transform.forward, playerDirection);
if(playerAngle <= fov / 2f){
inSight = true;
Debug.Log("PlayerinSight");
}else{
inSight = false;
}
if(inSight == true && PlayerDistance <= AwakeDistance){
AwareOFPlayer = true;
}
if (AwareOFPlayer == true)
{
enemyAgent.SetDestination(target.position);
}
}
}