Unity3D Enemy AI Tutorial

Unity3D Enemy AI Getting Started

This article is the first step for creating an Enemy AI or Enemy Behaviour Scripts.  In this tutorial series, we are going to learn about everything to make our Enemy smarter. 

Code

<pre class="brush:csharp;">
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyAi : MonoBehaviour {

    GameObject player;
    NavMeshAgent enemy;

	// Use this for initialization
	void Start () {

        player = GameObject.FindGameObjectWithTag(&quot;Player&quot;);

        if (player == null)
        {
            Debug.Log(&quot;Did u forgot to tag your player or FPS Controller&quot;);
        }


        enemy = GetComponent&lt;NavMeshAgent&gt;();


    }
	
	// Update is called once per frame
	void Update () {

        if (player != null)
            enemy.destination = player.transform.position;

    }
}</pre>

<p>&nbsp;</p>
0 Comments
Leave A Comment

Please login to post your valuable comments.

share