void Start()
{
Manager manager = GameObject.FindGameObjectWithTag("Manager").GetComponent<Manager>();
targets.AddRange(manager.turrets);
mainBase = manager.mainBase;
player = manager.btr.transform;
if (targets.Count != 0) target = targets[Random.Range(0, targets.Count)];
else target = null;
btr = player.GetComponent<BTR>();
}
void Z_Mov()
{
if (attacking) return;
if (nav.isOnNavMesh) nav.destination = target.position;
if (!stop && runner)
{
anim.SetBool("Attack", false);
anim.SetBool("Walk", false);
anim.SetBool("Run", true);
}
else if (!stop)
{
anim.SetBool("Attack", false);
anim.SetBool("Run", false);
anim.SetBool("Walk", true);
}
}
IEnumerator Check()
{
while (true)
{
if (hp > 0)
{
Collider[] colliders = Physics.OverlapSphere(center.position, 1.5f, layerMask);
if (colliders.Length == 0)
{
stop = false;
attacking = false;
yield return null;
}
else
{
foreach (Collider coll in colliders)
{
if (coll != null)
{
if (coll.transform.CompareTag("Player") || coll.transform.CompareTag("BTR"))
{
stop = true;
attacking = true;
btr.TakeDamage(Random.Range(25, 35));
}
else if (coll.transform.CompareTag("Turret"))
{
stop = true;
attacking = true;
coll.TryGetComponent(out Turret turret);
turret.TakeDamage(Random.Range(20, 30));
targets.RemoveAll(x => x == null);
}
else if (coll.transform.CompareTag("Base"))
{
stop = true;
attacking = true;
Base.TakeDamage(Random.Range(70, 90));
}
else
{
stop = false;
attacking = false;
}
yield return null;
}
yield return null;
}
}
yield return null;
}
else
{
Z_Stat();
yield return null;
}
yield return null;
}
}
void Z_Mov()
{
if (attacking) return;
if (nav.isOnNavMesh) nav.destination = target.position;
if (!stop && runner)
{
anim.SetBool("Attack", false);
anim.SetBool("Walk", false);
anim.SetBool("Run", true);
}
else if (!stop)
{
anim.SetBool("Attack", false);
anim.SetBool("Run", false);
anim.SetBool("Walk", true);
}
}
IEnumerator Check()
{
while (true)
{
if (hp > 0)
{
Collider[] colliders = Physics.OverlapSphere(center.position, 1.5f, layerMask);
if (colliders.Length == 0)
{
stop = false;
attacking = false;
yield return null;
}
else
{
foreach (Collider coll in colliders)
{
if (coll != null)
{
if (coll.transform.CompareTag("Player") || coll.transform.CompareTag("BTR"))
{
stop = true;
attacking = true;
btr.TakeDamage(Random.Range(25, 35));
}
else if (coll.transform.CompareTag("Turret"))
{
stop = true;
attacking = true;
coll.TryGetComponent(out Turret turret);
turret.TakeDamage(Random.Range(20, 30));
targets.RemoveAll(x => x == null);
}
else if (coll.transform.CompareTag("Base"))
{
stop = true;
attacking = true;
Base.TakeDamage(Random.Range(70, 90));
}
else
{
stop = false;
attacking = false;
}
yield return null;
}
yield return null;
}
}
yield return null;
}
else
{
Z_Stat();
yield return null;
}
yield return null;
}
}