I am making a Sci-Fi game where the player it’s on a planet without oxygen.
I want a script where the player health drains over time, and when he collides with some objects (Like his spaceship or dead bodies) he refills his health.
I tried to make it alone, but my coding it’s…rusty.
you may use coroutines ( im in C#) …
bool noOxygen;
bool drainingHealth = false;
void Update()
{
if (noOxygen && !drainingHealth)
{
drainingHealth = true;
StartCoroutine("DrainHealth");
}
}
IEnumerator DrainHealth()
{
health -= 1;
yield return new WaitForSeconds(secondsBetweenHealthDrain);
drainingHealth = false;
}
Ofcourse you need to adjust the time between drains of health happen ( best to adjust health drain time rather than drain amount, incase you do a health bar or something, that way it looks smoother)