Iv’e looked all over the documentation and cant find a thing that would do something like this:
forever
{
health -= 0.1f;
}
because that’s what it would be in python but don’t know about c#
can anyone help? I know its probably simple!
Iv’e looked all over the documentation and cant find a thing that would do something like this:
forever
{
health -= 0.1f;
}
because that’s what it would be in python but don’t know about c#
can anyone help? I know its probably simple!
you don’t want an infinite loop.
What are you trying to do? take health off once per frame?
ok so how do i do that?
You have to specify what you’re trying to do.
substract -0.1f per frame? per n frames? per second? per n seconds?
Please be more specific.
Usually, you don’t…if you do, Unity will freeze.
If you want to contiuously reduce a characters health, you can use Update(). This method is called every frame. Alternatively, you can use a coroutine and yield in every iteration of your infinite loop.
But if you really want an infinite loop, here is one:
while(true) {
//do stuff
}
But personally I prefer this way, since it reminds me that Unity is crying, if I use it improperly:
for(;;) {
//do stuff
}
You’re not going to want to reduce health per frame, because then the framerate dictates how fast your character dies.
To make health decrease over time, you need to determine the rate of decrease over time.
So this would run every frame, and be decreasing 5 health per second:
private void Update(){
health -= 5 * Time.deltaTime;
}
Ideally you would make a variable called “healthDegenRate” or “poisonDamage” or something descriptive to store that number rather than using it directly in the update.
thx for the help