I have an area where my player would stand and gradually regain health, In this case Its Oxygen because the game is in space. I have my players health gradually decreasing over a time, and when it reaches a specified area the health would regenerate. But the Regeneration script I have automatically shoots it up to full health when I want to see a gradual increase. As well as once it hits full health its begins to decrease again despite still standing in the zone. the colliders notify me that it is hitting, but it doesn’t work…
This is what I have
public class PlayerInfo : MonoBehaviour
{
public float MaxOxyLv = 100;
public float CurrentOxyLv;
private const float coef = 2;
// private const float recoef = 10f;
public OxyLvl Oxygen;
void Start()
{
CurrentOxyLv = MaxOxyLv;
Oxygen.SetMaxOxy(MaxOxyLv);
Oxygen.SetOxy(CurrentOxyLv);
}
void Update()
{
CurrentOxyLv -= coef * Time.deltaTime;
Oxygen.SetOxy(CurrentOxyLv);
if (CurrentOxyLv <= 0f)
{
Suffocate();
}
if (CurrentOxyLv <= 20f)
{
print (" LOW OXYGEN WARNING!");
}
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Recover" && CurrentOxyLv < MaxOxyLv)
{
Debug.Log ("Refueling");
Refuel();
}
// if(CurrentOxyLv > 99)
// {
// DoNothing();
// }
}
void Refuel()
{
CurrentOxyLv+= 10 *Time.deltaTime;
Oxygen.SetOxy(CurrentOxyLv);
}
// void DoNothing()
// {
// return;
// }
void Suffocate()
{
Debug.Log (“You Lose”);
}
}
I’ve been working on this for hours…