Unity筆記之常用工具類API

2021-08-14 02:38:56 字數 847 閱讀 7624

一、螢幕類

1.screen.width :靜態唯讀屬性,螢幕的寬度

screen.height:靜態唯讀屬性,螢幕的高度

這兩個值在unity開發中,取game視窗的高度寬度;在具體的裝置上執行,取具體裝置的高度寬度

二、時間類

1.time.time:靜態唯讀屬性,遊戲時間,即從遊戲開始到現在所經過的秒數

3.time.timescale:靜態屬性,時間縮放。可以用於遊戲暫停

三、數學類

1.mathf.abs() 絕對值

2.mathf.max() 最大值

3.mathf.min() 最小值

4.mathf.round() 四捨五入

5.mathf.lerp(float a, float b, float t):插值運算

基於浮點數 t 返回 a 與 b 之間的插值,t取0~1之間。當t分別時0,1,0.5時,函式分別返回a,b,a和b的平均值

同理有:vector3.lerp(vector3 a, vector3 b, float t)   可用於使攝像機對目標物體進行平滑跟隨

transform.position = vector3.lerp(transform.position, targetposition, time.deltatime*smoothing)

6.mathf.clamp(float value, float min, float max):限制取值

限制value的值在min和max之間, 如果value小於min,返回min。 如果value大於max,返回max,否則返回value 

常用工具類

本講內容 常用工具類 陸續更新 author administrator public static context context public void oncreate public static context getcontext 2 提供所有activity呼叫 基類 author ad...

常用工具類

reflectionutils objectutils public static void main string args 判斷兩個陣列是否相等 system.out.println arrays.equals arr,arr true 列印陣列 string s1 arrays.tostrin...

常用工具類 作業

1.生成10個 10,23 之間的隨機整數 random 類的nextdouble 或nextint 實現public class randomdemo for int i 1 i 10 i 1.以樹狀結構輸出計算機某個指定資料夾下的所有的檔案和子資料夾名稱。public class filedem...