Unity/C# 문법

[유니티] Mathf

Skull Crusher 2021. 5. 6. 15:06
728x90

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MathfTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        //절대값 : Mathf.Abs(float)
        float absVal = Mathf.Abs(-10f);
        Debug.Log("Mathf.Abs(절대값) : " + absVal);

        //최소 , 최대 제한
        float limit = Mathf.Clamp(9f, 10f, 20f);
        Debug.Log("Mathf.Clamp(값, 최소값, 최대값) : " + limit);

        //올림, 버림, 반올림
        float val = 12.1234f;
        Debug.Log("Mathf.Ceil(올림값) : " + Mathf.Ceil(val));
        Debug.Log("Mathf.Floor(버림값) : " + Mathf.Floor(val));
        Debug.Log("Mathf.Round(반올림값) : " + Mathf.Round(val));

        //각도 -> 라디안 변경
        float radian = 57.3f * Mathf.Deg2Rad;
        Debug.Log("57.3도 -> 라디안 : " + radian);

        //라디안 -> 각도 변경
        float degree = radian * Mathf.Rad2Deg;
        Debug.Log("1라디안 -> 각도 -> : " + degree);

        //양수와 음수를 구분(양수,0 => 1을 반환, 음수 => 0을 반환)
        float signVal = Mathf.Sign(-10);

    }

    // Update is called once per frame
    void Update()
    {
        // 범위 반복 : Mathf.Repeat(값, 최대값);
        Debug.Log("Time.time : " + Time.time);
        Debug.Log(Mathf.Repeat(Time.time, 3));
    }
}