码迷,mamicode.com
首页 > 编程语言 > 详细

小白_Unity引擎_Mathf

时间:2018-07-09 19:17:52      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:div   vector   style   pos   数值   取值   obj   mat   debug   

 

Ceil

1         //向上取值,向大取值
2         Debug.Log(Mathf.Ceil(0.1f)); //1
3         Debug.Log(Mathf.Ceil(0.9f));//1
4         Debug.Log(Mathf.Ceil(-0.1f));//0
5         Debug.Log(Mathf.Ceil(-0.9f));//0

 

Floor

1         //向下取值,向小取值
2         Debug.Log(Mathf.Floor(0.1f)); //0
3         Debug.Log(Mathf.Floor(0.9f));//0
4         Debug.Log(Mathf.Floor(-0.1f));//-1
5         Debug.Log(Mathf.Floor(-0.9f));//-1

 

Round 四舍五入

 1         //四舍五入
 2         Debug.Log(Mathf.Round(0.1f)); //0
 3         Debug.Log(Mathf.Round(0.9f));//1
 4         Debug.Log(Mathf.Round(-0.1f));//0
 5         Debug.Log(Mathf.Round(-0.9f));//-1
 6 
 7         //如果 遇到 0.5 时候会不一样, 结果看前一位
 8         /// 正数  偶数 --》  -0.5
 9         /// 负数  偶数 ---》  +0.5
10         /// 正数  奇数 --》  +0.5
11         /// 负数  奇数 --》  -0.5
12         Debug.Log(Mathf.Round(0.5f)); //1
13         Debug.Log(Mathf.Round(1.5f));//2
14         Debug.Log(Mathf.Round(-0.5f));//0
15         Debug.Log(Mathf.Round(-1.5f));//-2

 

Camp限制

 1         //Camp(value, min ,max)
 2         //限制:限制value的值在min 和 max之间,如果value小于min,返回min。
 3         //如果value大于max,返回max,返回max,否则返回value
 4         Debug.Log(Mathf.Clamp(12, 10, 20));//12
 5         Debug.Log(Mathf.Clamp(5, 10, 20));//10
 6         Debug.Log(Mathf.Clamp(25, 10, 20));//20
 7         //限制 0-1 之间,如果小于0返回0 ,如果大于1返回1,否则返回value
 8         Debug.Log(Mathf.Clamp01(0.1f));//0.1
 9         Debug.Log(Mathf.Clamp01(-0.1f));//0
10         Debug.Log(Mathf.Clamp01(2f));//1

 

插值

 1         //插值
 2         //第三个参数t :表示一个百分数,0-1,如果 t= 0.5f,那么返回值就从50%开始
 3         //1.第三个参数如果是固定值,则返回值是固定值根据参数大小而改变
 4         //2.第三个参数必须是0-1之间如果 <= 0 ,返回第一参数值,如果参数 >= 1 返回第2个参数
 5         // Mathf.Lerp(a, b, c)
 6         //原理 返回值 =  (b - a)*c + a ;
 7         Debug.Log(Mathf.Lerp(1, 100, Time.time));
 8         Debug.Log(Mathf.Lerp(1, 100, 0.5f));
 9         //物体匀速运动
10         obj.transform.position = new Vector3(Mathf.Lerp(0, 15, Time.time), 0, 0);
11 
12         //Mathf.LerpAngle(10, 100, Time.time);
13         obj.transform.eulerAngles = new Vector3(0, Mathf.LerpAngle(10, 100, Time.time), 0);

反插值

 

小白_Unity引擎_Mathf

标签:div   vector   style   pos   数值   取值   obj   mat   debug   

原文地址:https://www.cnblogs.com/CeasarH/p/9285217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!