- Home /
Question by
preventionflu · Aug 09, 2020 at 05:26 PM ·
playerdestroyhealth
My player wont get destroyed when he dies ,My player wont get destroyed when he dies
this is my code for health using System.Collections; using System.Collections.Generic; using UnityEngine;
public class HeartSystem : MonoBehaviour { public GameObject[] hearts; public GameObject Player; private int life; private bool dead;
private void Start()
{
life = hearts.Length;
}
void Update()
{
if (dead == true)
{
Destroy(Player.gameObject);
}
}
public void TakeDamage(int d)
{
if (life >= 1)
{
life -= d;
Destroy(hearts[life].gameObject);
if(life < 1)
{
dead = true;
}
}
}
} ,this is my code using System.Collections; using System.Collections.Generic; using UnityEngine;
public class HeartSystem : MonoBehaviour { public GameObject[] hearts; public GameObject Player; private int life; private bool dead;
private void Start()
{
life = hearts.Length;
}
void Update()
{
if (dead == true)
{
Destroy(Player.gameObject);
}
}
public void TakeDamage(int d)
{
if (life >= 1)
{
life -= d;
Destroy(hearts[life].gameObject);
if(life < 1)
{
dead = true;
}
}
}
}
Comment
have you actually checked if your lives are going down? also please don't post the same thing twice
Your answer
Follow this Question
Related Questions
Dying Problem! 1 Answer
Lose health on collision 1 Answer
Player Health 3 Answers
Regain health on GUI 2 Answers