Hi, im making a enemy AI script, and, i have an follow method, that make an enemy follow the player, when he is close, but, if i add another enemy with the same script, it work like an hive, i have to be in the range of the 2 enemys to they start following, and i dont want this, i want they work separatly, what i do? this is my code.`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public GameObject enemy;
public int health = 100;
public GameObject deathEffect;
public GameObject gold;
private Rigidbody2D rb;
private Vector2 movement;
public Animator anim;
public GameObject armadoinimigo;
public static bool morte;
public Transform goldlocal;
public Transform armalocal;
public GameObject armaitem;
public static bool isalive;
public float speed;
private Transform target;
public static bool correndo;
public static bool run;
public static bool die;
public Transform player;
public void TakeDamage (int damage)
{
health -= damage;
if (health <= 0)
{
Die();
isalive = false;
}
}
void Die()
{
Instantiate(gold, goldlocal.position, Quaternion.identity);
Instantiate(armaitem, armalocal.position, Quaternion.identity);
enemyshoot.isondistance = false;
correndo = false;
morte = true;
anim.SetBool("die", true);
armadoinimigo.SetActive(false);
die = true;
}
private void Update()
{
if (vida.vivo)
{
if (isalive)
{
if (enemyshoot.isondistance)
{
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}
}
}
if (die)
{
isalive = false;
enemyshoot.isondistance = false;
}
}
void Start()
{
isalive = true;
rb = this.GetComponent<Rigidbody2D>();
target = player.transform;
}
}
`