Unity3D Input按鍵系統

2021-06-22 14:28:48 字數 1800 閱讀 9875

新增新的虛擬軸,選擇選單edit->project settings->input :

unity 為你提供訪問ios/android系統的

input

和 ios input

指令碼介面。

多點觸控

觸控列表(input.touches):返回上一幀所有觸控狀態的物件列表(touch:單個觸控狀態)。

觸控狀態(touchphase):(例子:if(touch.phase != touchphase.began))

裝置面朝方向

input.deviceorientation : (例子:

if (input.deviceorientation == deviceorientation.facedown))

加速感測器

input.acceleration :豎直拿著裝置(home按鈕在底部),x軸指向右,y軸指向上,z軸指向前。

加速度感測器數值可能被顛簸影響。應用低通過過濾器可以是它平滑,擺脫干擾。

//

加速器重新整理間隔

float accelerometerupdateinterval = 1.0f / 60.0f;//

值越大, 被過濾值將匯集當前輸入取樣越慢

float lowpasskernelwidthinseconds = 1.0f;

//過濾範圍

private float

lowpassfilte***ctor = accelerometerupdateinterval / lowpasskernelwidthinseconds;

private vector3 lowpassvalue =vector3.zero;

void

start ()

//過濾方法 (獲取加速量呼叫此方法即可)

vector3 lowpassfilteraccelerometer()

通過iphonesettings.startlocationserviceupdates()方法開始定位服務的更新。

最後通過iphoneinput.lastlocation可以收回位置座標變數。

api: static void 

startlocationserviceupdates

( float 

desiredaccuracyinmeters 

= 10f,float 

updatedistanceinmeters

= 10f)

引數1:desiredaccuracyinmeters - 理想服務精確度(單位是公尺)。使用更高的值像500通常不需要開啟gps晶元從而保持電池電量,像5-10的值可以被用來得到最好的精確度。預設值是10公尺。

引數2:updatedistanceinmeters - 最小的距離(單位是公尺)的一種服務在橫向移動之前必須更新iphoneinput.lastlocation

屬性。像500意味著更少的開銷。預設的是10公尺。

void

start ()

//在20秒內服務沒有初始化

if (maxwait < 1

)

//使用者拒絕訪問定位服務

if (iphonesettings.locationservicestatus ==locationservicestatus.failed)

//被給予許可並且定位數值可以取回

else

//如果不需要持續查詢重新整理定位停止服務

iphonesettings.stoplocationserviceupdates();

}

Unity3D Input按鍵系統

新增新的虛擬軸,選擇選單edit project settings input unity 為你提供訪問ios android系統的 input 和ios input 指令碼介面。多點觸控 觸控列表 input.touches 返回上一幀所有觸控狀態的物件列表 touch 單個觸控狀態 觸控狀態 t...

Unity3D 參考座標系

參考座標系 reference coordinate system 列表是讓你指定用於變換 移動move 旋轉rotate和縮放scale 的座標系。選項包括檢視座標view,螢幕座標screen,世界座標world,父座標parent,區域性座標local,網格座標grid和拾取座標pick。在螢...

unity3d 參考座標系

參考座標系 reference coordinate system 列表是讓你指定用於變換 移動move 旋轉rotate和縮放scale 的座標系。選項包括檢視座標view,螢幕座標screen,世界座標world,父座標parent,區域性座標local,網格座標grid和拾取座標pick。在螢...