Duplicated Enemy Deaths
So, I have been working for a couple weekends on this project to have the ground works laid out for what will be my first real game. I had everything all ready to go, but I just had to go and test one more thing. I duplicated my enemy, and now am coming across the classic case of all my like enemies dying simultaneously. As far as I can tell, it is not the issue of a static variable, although I have been known to be wrong before. I tried to find an answer before making this post, but either I am dumb or there has not been a whole lot of luck for people with this problem when it was not caused be an unneeded "static". The first code is the primary one that deals with the majority of the enemy behavior. The second one specifically deals with combat behavior. If anyone can see the point where I am simply being blind, that would be most appreciated.
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class SpiderEnemy : MonoBehaviour
{
public int EnemyHealth = 10;
public GameObject TheSpider;
public int SpiderStatus;
public int BaseXP = 10;
public int CalculatedXP;
public static int Spider;
public GameObject ThePlayer;
public GameObject AttackSphere;
public GameObject DetectSphere;
public int RespawnX;
public int RespawnY;
public int RespawnZ;
public int EnemyArmor = 0;
void Update()
{
TheSpider.transform.LookAt(ThePlayer.transform);
if (InflictDamage.DeductPoints == true)
{
EnemyHealth -= InflictDamage.DamageAmount;
}
Spider = SpiderStatus;
if(EnemyHealth <= 0)
{
if (SpiderStatus == 0)
{
StartCoroutine(DeathSpider());
}
}
}
IEnumerator DeathSpider()
{
SpiderStatus = 6;
CalculatedXP = BaseXP;
yield return new WaitForSeconds(0.5f);
TheSpider.GetComponent<Animation>().Play("die");
AttackSphere.SetActive(false);
Experience.CurrentXP += CalculatedXP;
GoldCount.GoldValue += 1;
yield return new WaitForSeconds(3.0f);
TheSpider.transform.position = new Vector3(RespawnX, RespawnY, RespawnZ);
yield return new WaitForSeconds(1.0f);
EnemyHealth = 10;
SpiderStatus = 0;
TheSpider.GetComponent<Animation>().Play("idle");
AttackSphere.SetActive(true);
DetectSphere.SetActive(true);
AttackPlayer.DealingDamage = 0;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackPlayer : MonoBehaviour
{
public GameObject TheEnemy;
public float EnemySpeed;
public static int DealingDamage;
public GameObject DetectSphere;
public int Damage;
void Update()
{
if(LeatherArmor.ArmorBonus >= 5)
{
Damage = 1;
}
if(LeatherArmor.ArmorBonus < 5)
{
Damage = 5 - LeatherArmor.ArmorBonus;
}
}
void OnTriggerEnter(Collider other)
{
DetectSphere.SetActive(false);
}
void OnTriggerStay(Collider other)
{
if (DealingDamage == 0)
{
EnemySpeed = 0f;
TheEnemy.GetComponent<Animation>().Play("attack");
StartCoroutine(HurtPlayer());
}
}
void OnTriggerExit(Collider other)
{
DetectSphere.SetActive(true);
}
IEnumerator HurtPlayer()
{
DealingDamage = 2;
yield return new WaitForSeconds(0.5f);
if (SpiderEnemy.Spider != 6)
{
Health.HealthValue -= Damage;
LeatherArmorSkill.LeatherArmorEXP += LeatherArmor.ArmorBonus;
}
yield return new WaitForSeconds(0.5f);
DealingDamage = 0;
}
}