using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(UnityEngine.AI.NavMeshAgent))]
public class EnemyScript : MonoBehaviour
{
private Animator EnemyAnim;
private NavMeshAgent navMesh;
private GameObject player;
public float enemySpeed;
void Start()
{
EnemyAnim = GetComponent();
navMesh = GetComponent();
player = GameObject.FindGameObjectWithTag("Player");
navMesh.speed = enemySpeed;
}
void Update()
{
navMesh.destination = player.transform.position;
EnemyAnim.SetBool("Walking", true);
if(Vector3.Distance(transform.position, player.transform.position) < 1.5f){
navMesh.speed = 0;
EnemyAnim.SetBool("Attack", true);
StartCoroutine("Att");
}
}
IEnumerator Att()
{
yield return new WaitForSeconds(2.8f);
EnemyAnim.SetBool("Attack", false);
navMesh.speed = enemySpeed;
}
}
would it be possible to locate a gameObject(clone) from a tag? I'm desperate for this answer as I'm trying to script my enemy's AI, and I need it to locate my player tag which is a clone of a prefab template created from a spawn script.
would it be possible to locate a gameObject(clone) from a tag? I'm desperate for this answer as I'm trying to script my enemy's AI, and I need it to locate my player tag which is a clone of a prefab template created from a spawn script.
↧