unity之Mathf常用函数

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

public class API10Mathf : MonoBehaviour {


    public Transform cube;
    // Use this for initialization
    void Start() {
        Debug.Log(Mathf.Rad2Deg);
        //角度变度数
        Debug.Log(Mathf.Deg2Rad);
        //度数变角度
        Debug.Log(Mathf.Infinity);
        //正无穷
        Debug.Log(Mathf.Epsilon);
        //极小值
        Debug.Log(Mathf.PI);
        Debug.Log(Mathf.NegativeInfinity);
        //负无穷
        Debug.Log(Mathf.Ceil(10.2f));
        //向上取整
        Debug.Log(Mathf.Floor(10.2f));
        //向下取整
        Debug.Log(Mathf.Pow(2,5));
        //2的5次方
        Debug.Log(Mathf.Sqrt(5));
        //5的平方根
        Debug.Log(Mathf.Max(5,6));
        Debug.Log(Mathf.Min(5, 6));
        //大小比较
        Debug.Log(Mathf.ClosestPowerOfTwo(5));
        //返回最近的2的次方数

        cube.position = new Vector3(0, 0, 0);
    }

    // Update is called once per frame
    void Update() {
        //cube.position = new Vector3(Mathf.Clamp(Time.time, 1f, 3f), 0, 0);
        //Mathf.Clamp,限定只在某个范围之内,主要运用场景,控制血量蓝量
        //Debug.Log(Mathf.Clamp(Time.time, 1f, 3f));
        float x = cube.position.x;
        //float newx = Mathf.Lerp(x, 10, 0.1f);
        // Mathf.Lerp按比例取两者的之差

        //float newx = Mathf.MoveTowards(x, 10, Time.deltaTime);
        //Mathf.MoveTowards匀速移动
        // cube.position = new Vector3(newx, 0, 0);

        cube.position = new Vector3(Mathf.PingPong(Time.time*3, 10) - 5, 0, 0);
        //Mathf.PingPong返回一个在0到10之间的数
    }
}

 

你可能感兴趣的:(Unity学习之旅)