Hi guys! I’m currently making a Co-op Zombie Apocalypse Survival Game.
But there’s on problem. The Zombie follow just the newest GameObject with “Player” Tag. not the old one Is there any way to fix it?
Btw Here’s the Script i tried:
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 = null;
}
void Update ()
{
if(Vector3.Distance(GameObject.FindWithTag("Player").transform.position, myTransform.position) < minRange)
{
player = GameObject.FindWithTag("Player").transform;
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;
}
}
}
Any Ideas :)?