- Home /
how to add x value in y seconds
hi.im coding a game but i am having some trouble
float sure;
float deger;
void Update(){
sure = sure + 1 * Time.deltaTime;
if (sure == 10f)
{
sure = 0;
deger += 1;
}
}
this is my code "sure" gains value every second but when it came to ten it doesnt be zero "deger" value cant grow how to solve this?
Answer by Commoble · Feb 07, 2018 at 06:12 PM
Instead of checking if (sure == 10F)
, check for if (sure >= 10F)
and then reset your numbers as needed.
You generally don't want to use ==
when you're comparing floats, especially when you're adding something like Time.deltaTime to a float -- your number will virtually never equal exactly 10F.
Your answer
![](https://koobas.hobune.stream/wayback/20220612152147im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sorting a list based of a variable 1 Answer
How can i List objects by name but also in small text or big text or any kind ? 1 Answer
How can i make an entrance and exit in this maze ? 1 Answer
How can I animate linerenderer lines over time ? 1 Answer
How can i find a thirdpersoncontroller hand and attach object to the hand ? 1 Answer