My checker work 2 times
So, i writing a code where is enemy taking damage when special object is active
void DmgCheck()
{
if (Yellow.gameObject.activeSelf)
{
hp[enemyID] -= dmgHero;
}
else if (Red.gameObject.activeSelf)
{
hp[enemyID] -= dmgHero;
}
else if (Green.gameObject.activeSelf)
{
hp[enemyID] -= dmgHero;
}
}
This is code for my enemy
public void OnTriggerStay2D(Collider2D pointer)
{
if (attack == false)
{
greenAttack.SetActive(false);
yellowAttack.SetActive(false);
redAttack.SetActive(false);
}
if (pointer.gameObject.CompareTag("Green") && (attack == true))
{
greenAttack.SetActive(true);
attack = false;
hero.transform.position = new Vector3(-7,3,-1);
Debug.Log("green");
}
else if (pointer.gameObject.CompareTag("Yellow") && (attack == true))
{
yellowAttack.SetActive(true);
attack = false;
hero.transform.position = new Vector3(-7, 3, -1);
Debug.Log("yellow");
}
else if (pointer.gameObject.CompareTag("Red") && (attack == true))
{
redAttack.SetActive(true);
attack = false;
hero.transform.position = new Vector3(-7, 3, -1);
Debug.Log("red");
}
}
And this is my code for activator
So, in game enemy taking hit two times and i dont know why.
Comment