Enemy Old Script
Enemy Old Script
Collections;
using System.Collections.Generic;
using UnityEngine;
void Start()
{
animator = GetComponent<Animator>();
navAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
player = GameObject.Find("PlayerBodyobj").transform;
isDead = false;
isSafe = true;
}
if (randomDeathValue == 0)
{
animator.SetTrigger("DIE");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 1)
{
animator.SetTrigger("DIE1");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 2)
{
animator.SetTrigger("DIE2");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 3)
{
animator.SetTrigger("DIE3");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 4)
{
animator.SetTrigger("DIE4");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 5)
{
animator.SetTrigger("DIE5");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 6)
{
animator.SetTrigger("DIE6");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 7)
{
animator.SetTrigger("DIE7");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 8)
{
animator.SetTrigger("DIE8");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 9)
{
animator.SetTrigger("DIE9");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
if (randomDeathValue == 10)
{
animator.SetTrigger("FUNNYDEATH");
isDead = true;
animator.SetBool("ISDEAD", true);
Invoke("DEATH", deathDelay);
}
}
else
{
animator.SetTrigger("DAMAGE");
print("Health is now at " + EnemyHP + ".");
}
void DEATH()
{
animator.SetBool("HASBEENKILLED", true);
}
void Update()
{
if (isDead == false)
{
//Orientation
Vector3 viewDir = currentPos.position - new Vector3(transform.position.x,
currentPos.position.y, transform.position.z);
orientation.forward = viewDir.normalized;
else
{
print("EnemyisDead");
}
}
}
void FindSafeSpace()
{
if (isDead == false)
{
navAgent.SetDestination(ESCube.position);
GetComponent<UnityEngine.AI.NavMeshAgent>().speed = 8;
//Walkpoint reached
if (distanceToPoint.magnitude < 1f)
isSafe = true;
Invoke("HealingInSafeSpace", healingDelay);
}
}
void HealingInSafeSpace()
{
if (isDead == false)
{
EnemyHP = EnemyHP + 30;
if (EnemyHP < 70)
Invoke("HealingInSafeSpace", healingDelay);
}
void Retreat()
{
}
void StandOff()
{
void ChargePlayerSpawn()
{
if (isDead = false)
navAgent.SetDestination(PSCube.position);
}
/*/
Making the Standoffs, attacking and retreating work.
int CountNearbyAllies()
{
//I would consider changing this to OverlapSphereNonAlloc to reduce gc
stutter
var hits = Physics.OverlapSphere(this.transform.position,
allyDetectionRange, whatIsCurrentAlly); //use those customizable variables instead
int cnt = 0;
//one fatal flaw here is that if the enemy consists of more than 1 collider
tagged 'enemy', it'll count multiple times.
//you may want to consider some method of relating an enemy all together as
a single entity.
foreach(var c in hits)
{
if(c.CompareTag("Enemy")) //use CompareTag, not tag ==
{
cnt++;
}
}
return cnt;
}
int CountNearbyPlayerAllies()
{
//I would consider changing this to OverlapSphereNonAlloc to reduce gc
stutter
var hits = Physics.OverlapSphere(this.transform.position,
playerAllyDetectionRange, whatIsPlayerAlly); //use those customizable variables
instead
int cnt = 0;
//one fatal flaw here is that if the enemy consists of more than 1 collider
tagged 'enemy', it'll count multiple times.
//you may want to consider some method of relating an enemy all together as
a single entity.
foreach(var c in hits)
{
if(c.CompareTag("PlayerAlly")) //use CompareTag, not tag ==
{
cnt++;
}
}
return cnt;
}
/*/
Old script