In this Unity tutorial, I show you guys how to make a basic patrolling enemy AI in Unity. This is not an advanced tutorial, just something more basic and simple.
#Unity #Unity3D #Unity2021
For more Halo Infinite videos or Halo videos in general - be sure to like, comment, subscribe, and turn on notifications for more! 👍
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class chasePlayer : MonoBehaviour
{
public Vector3 destination;
public Transform Player, patrol;
public NavMeshAgent agent;
public GameObject cube;
public bool spotted;
public float searchTime;
void Update(){
if(spotted == false){
cube.SetActive(false);
destination = patrol.position;
agent.destination = destination;
}
if(spotted == true){
cube.SetActive(true);
destination = Player.position;
agent.destination = destination;
}
}
void OnTriggerEnter(Collider other){
if(other.CompareTag("Player")){
spotted = true;
}
}
void OnTriggerExit(Collider other){
if(other.CompareTag("Player")){
StartCoroutine(search());
}
}
IEnumerator search(){
yield return new WaitForSeconds(searchTime);
spotted = false;
}
}
Follow me on Twitter:
[ Ссылка ]
Try out my games:
[ Ссылка ]
Forgehub:
[ Ссылка ]
Subscribe to my Second Channel:
[ Ссылка ]
Join my Discord:
[ Ссылка ]
Facebook Page:
[ Ссылка ]
Follow me on Instagram:
[ Ссылка ]
Music Used:
glue70 - Black Rock
Lost Sky - Dreams [NCS Release]
C418 - Blocks
Ещё видео!