Hi, im writing a 2D Game and I have a power bar which shall be filled when an enemy is killed. The problem it isnt working. Oh and my Death Animation of the enemyisn’t working too. Here’s my code:
public class Enemy : MonoBehaviour
{
public float health = 1;
public bool isDead = false;
public float damage = 1;
Animator anim;
MummyWalk walk;
void ApplyDamage(float damage)
{
health -= damage;
if (health <= 0)
{
Debug.Log("ApplyDamage geht");
isDead = true;
KillCounter.killCounter.killcount = KillCounter.killCounter.killcount + 1;
Death();
}
}
void Death()
{
Debug.Log("Death Funktion geht");
isDead = true;
anim.SetTrigger("mummy_death");
walk.enabled = false;
}
public class HealthController : MonoBehaviour
{
private float power = 0;
public float startPower = 0;
private float maxPower = 100;
public Image powerGUI;
Enemy enemy;
void Start ()
{
if(Application.loadedLevel == 0)
{
power = startPower;
}
else
{
power = PlayerPrefs.GetFloat("power");
}
UpdateView();
}
void UpdateView()
{
if(enemy.isDead == true && powerGUI.fillAmount != maxPower )
{
powerGUI.fillAmount = maxPower / power;
}
}