What is Unity Mathf.Ceil?
Hello friends, today I want to talk to you about a function in Unity that sometimes comes in handy, our function is "Mathf.ceil()".
What is Unity Mathf.Ceil?
Now let's explain what this code does.The Ceil function is generally used in Unity to round numbers.
If we need to give an example;
void round(){
Debug.Log(Mathf.ceil(10.0)); // Will output 10
Debug.Log(Mathf.ceil(10.2)); // Will output 11
Debug.Log(Mathf.ceil(10.7)); // Will output 11
Debug.Log(Mathf.ceil(-10.0)); // Will output -10
Debug.Log(Mathf.ceil(-10.2)); // Will output -10
Debug.Log(Mathf.ceil(-10.7)); // Will output -10
}
How to Use Mathf.Ceil?
Actually, you may have already understood more or less how the ceil function works from above. The Ceil function is the one that rounds numbers up to the nearest integer for us.To use it, just write it as "Mathf.ceil(float-double number);" and assign it to a variable.
float float_number = 5.7f;
int integer = Mathf.ceil(float_number); // Will output 6.


Yorum Gönder