Hi Guys! I want to make a Strategy Zombie Survival RPG but, I have no idea how i shall make it work
It’s Scripted in C#. I want the AI, Target a Tag when that tag Comes near. How shall i make it?
I’ve already got a Follow Script Here:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour
{
public int minRange;
public bool follow;
public float moveSpeed;
public float rotationSpeed;
private Transform myTransform;
public Transform player;
void Start()
{
myTransform = transform;
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update ()
{
if(player == null) {
player = GameObject.FindGameObjectWithTag("Player").transform;
if(player.name == "Cube (Transform)") {
player = GameObject.FindGameObjectWithTag("Player").transform;
}
}
if(player != null && Vector3.Distance(player.position, myTransform.position) < minRange)
{
follow=true;
}else{
follow=false;
}
if(follow && player != null)
{
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(player.position - myTransform.position), rotationSpeed * Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}