Basic Patrolling Enemy AI in Unity - Unity C# Tutorial

Basic Patrolling Enemy AI in Unity - Unity C# Tutorial

Channel:
Subscribers:
12,600
Published on ● Video Link: https://www.youtube.com/watch?v=ploU82inrCw



Category:
Tutorial
Duration: 8:15
1,071 views
23


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:
https://twitter.com/omogonix

Try out my games:
https://omogonixlachlan.itch.io

Forgehub:
https://www.forgehub.com/members/omogonix.87700/

Subscribe to my Second Channel:
https://www.youtube.com/channel/UCkylkvUtpvbHfafGfIdMLBQ/featured

Join my Discord:
https://discord.gg/a88vmGD

Facebook Page:
https://www.facebook.com/Omogonix/

Follow me on Instagram:
https://www.instagram.com/uwugonixhalo/

Music Used:
glue70 - Black Rock
Lost Sky - Dreams [NCS Release]
C418 - Blocks







Tags:
unity
unity tutorial
how to
unity how to
how to unity
how to make a game
unity ai
unity ai tutorial
unity nav mesh agent
tutorial
ai
omogonix
basic
unity c#
csharp
c#
unity 3d
game development
game development tutorial
unity patrolling enemy ai
patrolling enemy ai
unity basic enemy ai
basic enemy ai
enemy ai
basic ai
coding
how to use csharp
basic unity tutorial
simple
simple unity tutorial