So I am trying to set up a system in which my character will become sick when out in the rain too long.I originally used a float and Time.time, then i realised that wont work because after a certain time it will always be active.
so i decided to increment the float simply using ++ and set the system up that way. However this is still causing issues, Is there a way for to to basically say if sickness has been active for period of time, then do next thing?
This is what I am currently working with, but failing. Any help would be appreciated
this is the type of structure I would start with.
Your code just has if statement after if statement. You need some else statements to help with the logic.
I will try this out. I would still like to use a time system, So I can if he is outside and sick for a specific amount of time, he will get sicker. I dont want to have it so that it happens instantly. Do you know a way to do this
You’ll need to tell me about the scene. I assume you have a script on the player. This script detects when the player is outside, some kind of collider or something. doesn’t really mater. But when it’s outside you have to start the timer. I assume the bool Outside is set to true.
I like the timer idea of. typically I do a Time.Deltatime
float time = 0;
time += Time.Deltatime;
if(time > 98f)
{
//do something
}
This isn’t great, but maybe it’s a start for you. The issue is that I’m not using the outsidetime to do anything.
and the wetness can go to negative numbers.
Sorry for any typos, I free handed the code.
float OutSideTime = 0;
void SicknessSystem()
{
if(Outside)
{
//player is outside
OutSideTime += Time.DeltaTime;
if(Raining)
{
//it's raining so wetness will increase
Wetness++;
GetsSicker();
}else
{
//not raining, do nothing
}
}else
{
//player is inside
OutSideTime = 0;
if(NearFire)
{
//at a worm fire
Wetness = Wetness - 5; // dry fast
GetsBetter();
}else
{
// not at a fire
Wetness--; // dry slow
GetsBetter();
}
}
}
void GetsSicker()
{
//check wetness
if (Wetness >= 99f && pnemoniaTime > 200f) // always start with the least likely this to be true
{
pneumonia1 = true;
pnemoniaTime++;
}else if (Wetness >= 98f)
{
pnemoniaTime++;
}
}
void GetsBetter()
{
pnemoniaTime--;
}
I have not tried out the code yet, but just wanted to update with the questions you asked.
The wetness increases when it is raining and the player goes outside. The pnemoniaTime was what I was using as a float to keep track of time.
The way I had it somewhat works, but when the player goes inside and next to fire, the pnemoniaTime continues to count, until around 200. Im not sure why it continues to count for that short amount of time, but if it didnt it would work.
I will try out the code and let you know if it works, thanks alot