I am making a small horror game to practice in unity. I’m trying to have health decrease if you have your flashlight. If the flashlight is off the player is supposed to have their health slowly decrease until they can turn the light back on or get into a well let area.
The problem is I can’t get the health to decrease slowly over time with the Time.Deltatime code to work.
Here’s the code \
if (light.enabled == false)
{
GameObject player = GameObject.Find (“First Person Controller”);
PlayerHealth playerhealth = player.GetComponent ();
playerhealth.curHealth -= Time.deltaTime/10;
The thing is you’re attempting to convert a float to an int. When you do “Time.deltaTime / 10”, the result should be > 0 and < 1 (0.01 like I said). But “curHealth” is an int so the value will be cast and you’ll get … 0 ! You’re trying to remove 0 from curHealth (basically, you’re removing nothing).
Either you change your curHealth to float or you set a minimum value when decreasing player’s health (like 1).