I simply would like to know if there is a way to truncate a 2D texture (in the GUI), in order to create a drawn health gauge that cannot be repeated. I tried many methods, but they all scale the texture, and don’t truncate it.
I searched for a long time but couldn’t find this basic function.
I would be really grateful if someone knows a solution.
I have to use the Round function to have the closest integer. But it seems that this function only works on numbers, and not on variables. On variables, it always changes the float to… a 0.
I don’t know why. I think I’ll have a headache -_-’
I managed to do what I wanted by multiplying the first member of the division (so it still rounds the result, but don’t returns 0 anymore).
But I still don’t understand why Unity rounds a division in a float.
Remember 27/40 is less than 1. That means as an int it can get truncated to 0.
27 and 40 are both ints. Therefore 27(int) / 40(int) is 0(int).
try dividing 27.0 with 40.0.
I don’t use Javascript often, I prefer C#, but I suggest that you explicitly state your types. Otherwise you will end up with Javascript choosing something you don’t want.
The other option is to mutliply both values by 1000 before dividing and hten removing hte 1000:
((27 * 1000) / (40 * 1000)) / 1000
It’s clunky but it is another way of getting higher accuracy if you need ints, and may lose precision partway through the calculation.