DanTheManForth
New member
- Joined
- Sep 6, 2018
- Messages
- 2
- Programming Experience
- Beginner
Hello all. I literally just started learning C# from knowing less than zero about coding at all. I am trying to program a basic FPS health system and am struggling to figure out things like coding inversely proportional relationships and making processes stop after reaching a certain level: the "health" and "acumen" aren't supposed to increase when "thirst" or "hunger are at max... but they do anyway. And "health" and "acumen" are supposed to stop regenerating when they hit max ... but they don't. I also cant figure out how to make "acumen" go down at the same rate that "pain" goes up. And when "health" gets to zero the player is supposed to "die" and everything stop ... but "health" keeps going down past zero and it keeps dying infinitely instead.
I have pasted my code below, in the hopes that someone could tell me what I am doing wrong or even just doing poorly. I kinow I am probably missing something obvious, and I apologize for the glaring amateurish language.
I have pasted my code below, in the hopes that someone could tell me what I am doing wrong or even just doing poorly. I kinow I am probably missing something obvious, and I apologize for the glaring amateurish language.
C#:
{
// variables
//private float maxHealth, maxThirst, maxHunger, maxPain, maxAcumen;
public float maxHealth, maxThirst, maxHunger, maxPain, maxAcumen;
public float thirstIncreaseRate, hungerIncreaseRate, healthIncreaseRate, painIncreaseRate, acumenIncreaseRate;
public float painDecreaseRate, healthDecreaseRate, acumenDecreaseRate;
public float health, thirst, hunger, pain, acumen;
private float maxAcumenIncreaseRate;
private bool playerDeath;
// functions
public void Start()
{
health = maxHealth;
acumen = maxAcumen;
maxAcumenIncreaseRate = 0.0001f; // player max acumen increases appriximately 1 point per 3 hours
}
public void Update()
{
// thirst, hunger, health, acumen, and max acumen gradually increase
if (!playerDeath)
{
thirst += thirstIncreaseRate * Time.deltaTime;
hunger += hungerIncreaseRate * Time.deltaTime;
maxAcumen += maxAcumenIncreaseRate * Time.deltaTime;
}
// health regenerates to max if hunger and thirst are below max
if (thirst < maxThirst && hunger < maxHunger)
{
health += healthIncreaseRate * Time.deltaTime;
}
// acumen regenerates to max if hunger and thirst are below max and pain is zero
if (thirst < maxThirst && hunger < maxHunger && pain <= 0f)
{
acumen += acumenIncreaseRate * Time.deltaTime;
}
// health and acumen gradually decrease when thirst and/or hunger are at max
if (thirst >= maxThirst)
{
health += healthDecreaseRate * Time.deltaTime;
acumen += acumenDecreaseRate * Time.deltaTime;
}
if (hunger >= maxHunger)
{
health += healthDecreaseRate * Time.deltaTime;
acumen += acumenDecreaseRate * Time.deltaTime;
}
// pain gradually decreases over time
if (pain >= maxPain)
{
pain += painDecreaseRate * Time.deltaTime;
}
// player dies at zero health
if (health <= 0)
{
playerDeath = true;
print("You Have Died");
}
}
}