Question by
RedKolikol · Sep 03, 2019 at 08:18 AM ·
gamesstateshealth
How to lose health when you enter a current "room" state.
I have currently made a health system, but i don't know how i can implement it on to an state. I'm creating a starter game that is a "create your own adventure" type, and i want to make it so when you select certain paths, you lose health. Here is the health script:
{
public Slider healthBarSlider;
public int currentHealth;
public int maxHealth;
public Text healthText;
bool isDead;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
}
// Update is called once per frame
void Update()
{
healthBarSlider.maxValue = maxHealth;
healthBarSlider.value = currentHealth;
healthText.text = currentHealth.ToString() + " / " + maxHealth.ToString();
if(currentHealth <= 0)
{
if(isDead)
{
return;
}
Dead();
}
if(Input.GetKeyDown(KeyCode.Return))
{
currentHealth -= 5; // You can change the value of damage one takes.
}
}
void Dead()
{
isDead = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
GUI Texture slide down || Clipping mask. 0 Answers
Getting Hit direction to show hit indicator 1 Answer
Having a small problem with the player getting a "free hit" before they die 0 Answers
If statement noop :) 1 Answer
Adding Multiple Vignettes 0 Answers