Math方法
其实内容是比较简单的,只是笔者想想养成记笔记的习惯,所以我们直接看代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MaTh : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log(Mathf.Lerp(1.0f, 3.0f, 0.5f));//按百分比取值,打印出的应该是2.0、
Debug.Log(Mathf.Clamp(1, 3, 5));//(int value,int min,int max)
Debug.Log(Mathf.Max(1, 10));//打印最大值;
Debug.Log(Mathf.Min(1, 10));//打印最小值;
Debug.Log(Mathf.Abs(-3));//取绝对值
Debug.Log(Mathf.Sin(20));//按弧度取得;
}
// Update is called once per frame
void Update()
{
}
//Awake --> Start --> Update --> FixedUpdate --> LateUpdate -->OnGUI -->Reset --> OnDisable -->OnDestroy Unity脚本函数执行顺序
}
**(1)**Mathf.Lerp方法
Debug.Log(Mathf.Lerp(1.0f, 3.0f, 0.5f));
第一个参数和第二个参数是范围,返回的是前两个参数按第三个参数百分比的取值,也即:返回值=(参数二-参数一)*参数三;
**(2)**Mathf.Clamp方法
Debug.Log(Mathf.Clamp(1, 3, 5))
第一个参数为返回值,参数二与参数三为范围,如果第一个参数在范围内,则返回,如果小于第一个参数则返回参数二,大于第三个参数则返回参数三。
Random方法
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RanDom : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int a = Random.Range(0, 10);//随机取值在0~10之间。
float b = Random.Range(0.0f, 0.9f);//随机取值在0与0.9之间
Debug.Log(a);
Debug.Log(b);
}
// Update is called once per frame
void Update()
{
}
}
小结 想渐渐的找回当初认真读书的感觉,一点一点的积累。一起加油吧!