How to take the percentage of a number in Unity/c#
It is very common in the development of game programming in Unity, having to take the percentage of a number with reference to a second value.
For this it is very easy, just have 3 parameters:
1 = Valuecurrent.
2 = Maximum Value.
3 = FactorDeMultiplo = In this example is 1, because I want a percentage of 0 to 1. If you wanted a value from 0 to 100, then the FactorDeMultiplo value would be 100.
float percent = (ValorCurrent / ValorMaximo) * 1;
Did you like this content? Let's talk...
I'm a game developer, I use unity. If you want to develop something, tell me!