❔ Getting The number when it goes over 100?
Hi, ive been trying to learn c# for a few weeks and ive ran into a problem and cant properly word it to search google with, i have 2 objects where i can walk into them and they give points, the points value is 70 and everytime points go to 100, it resets the points back to 0 which is kinda as intended? Im sure youve lost many brain cells trying to read this but my problem is that i want the value to be 70 but when i pick another drop back up i dont want it to go to 0 but to go to 40...? if no one understands this pls lmk, ill try give it another go XD
I Do apologise.
19 Replies
show what you tried
btw
levelBar.Value == 100f || levelBar.value > 100f
can be shortened to levelBar.Value >= 100f
agh, i see! thank you 🙂
so if u got 140 points, u want it to reset to 40 for example?
yes, basically.
TheRanger#3357
REPL Result: Success
Result: int
Compile: 262.672ms | Execution: 21.633ms | React with ❌ to remove this embed.
use the % operator
in ur case
Thanks for your help! im not sure if im not understanding how to use it or im just being seriously stupid?
but...
it returns 0?
well if it returned 0 it means originally the value was 100
it starts at 0 and jumps in 70s.
try debugging the value before you apply the % operator on it
starts at 0, goes to 70 then back to 0
u sure? show a screenshot of ur code with the debug messages
do u have a debug.Log somewhere else that prints the value?
i have it in Update()
it probably called the debug.Log from Update() not the one in checkLevel()
do something like
Debug.Log("from checkLevel: " + levelBar.value);
to indicate that this code is being called from that method
i can guess whats going onohhhhhhhhhhhh
goddamn im stupid
im sorry man, the values are coming from a slider with the max number being 100...
i doubt the if condition in the checkLevel method will ever be satisfied
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.