Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Mathf structrue for mathematical operations

Notes:

C# Unity Mathf structure: [Starts at: 00min:53sec]

C# Mathf structure contains constants and static methods for trigonometric, logarithmic, and other common mathematical operations.

Example Code:
using UnityEngine;
public class MathfStructure : MonoBehaviour {
void Start () {
float absOfNum = Mathf.Abs (-9.8f);
Debug.Log (absOfNum); // 9.8

Debug.Log(Mathf.RoundToInt(2.6f)); // 3
Debug.Log(Mathf.CeilToInt(2.6f)); // 3
Debug.Log(Mathf.FloorToInt(2.9f)); // 2

Debug.Log(Mathf.Pow(3,2)); // 9

//public static float Clamp(float value, float min, float max);
//Clamps a value between a minimum and maximum value.
Debug.Log(Mathf.Clamp(500f, 0f, 100f)); // 100

//public static float Lerp(float a, float b, float t);
// Linearly interpolates between a and b by t.
Debug.Log(Mathf.Lerp(0f, 100f, 0.5f)); // 50

int r = 4;
Debug.Log(Mathf.PI * Mathf.Pow(r,2)); // 50.26548

}
}