Unity3d 陀螺儀
http://blog.csdn.net/quannenggou/article/details/7513242
private var gyroBool : boolean;
private var gyro : Gyroscope;
private var rotFix : Quaternion;
function Start() {
var originalParent = transform.parent; // check if this transform has a parent
var camParent = new GameObject ("camParent"); // make a new parent
camParent.transform.position = transform.position; // move the new parent to this transform position
transform.parent = camParent.transform; // make this transform a child of the new parent
camParent.transform.parent = originalParent; // make the new parent a child of the original parent
gyroBool = Input.isGyroAvailable;
if (gyroBool) {
gyro = Input.gyro;
gyro.enabled = true;
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
camParent.transform.eulerAngles = Vector3(90,90,0);
} else if (Screen.orientation == ScreenOrientation.Portrait) {
camParent.transform.eulerAngles = Vector3(90,180,0);
}
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
rotFix = Quaternion(0,0,0.7071,0.7071);
} else if (Screen.orientation == ScreenOrientation.Portrait) {
rotFix = Quaternion(0,0,1,0);
}
//Screen.sleepTimeout = 0;
} else {
print("NO GYRO");
}
}
function Update () {
if (gyroBool) {
var camRot : Quaternion = gyro.attitude * rotFix;
transform.localRotation = camRot;
}
}
private var gyroBool : boolean;
private var gyro : Gyroscope;
private var rotFix : Quaternion;
function Start() {
var originalParent = transform.parent; // check if this transform has a parent
var camParent = new GameObject ("camParent"); // make a new parent
camParent.transform.position = transform.position; // move the new parent to this transform position
transform.parent = camParent.transform; // make this transform a child of the new parent
camParent.transform.parent = originalParent; // make the new parent a child of the original parent
gyroBool = Input.isGyroAvailable;
if (gyroBool) {
gyro = Input.gyro;
gyro.enabled = true;
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
camParent.transform.eulerAngles = Vector3(90,90,0);
} else if (Screen.orientation == ScreenOrientation.Portrait) {
camParent.transform.eulerAngles = Vector3(90,180,0);
}
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
rotFix = Quaternion(0,0,0.7071,0.7071);
} else if (Screen.orientation == ScreenOrientation.Portrait) {
rotFix = Quaternion(0,0,1,0);
}
//Screen.sleepTimeout = 0;
} else {
print("NO GYRO");
}
}
function Update () {
if (gyroBool) {
var camRot : Quaternion = gyro.attitude * rotFix;
transform.localRotation = camRot;
}
}
相關文章
- Xamarin Essentials教程陀螺儀GyroscopeROS
- iOS中陀螺儀的使用iOS
- 對js陀螺儀的認知理解JS
- 智慧掃地機器人陀螺儀構建地圖導航方案機器人地圖
- JavaScript 陀螺儀檢測裝置方向(重力感應)JavaScript
- iOS學習筆記34 加速計和陀螺儀iOS筆記
- 【cartographer_ros】五: 釋出和訂閱陀螺儀Imu資訊ROS
- 深度的Android感測器:近距離和陀螺儀 (有原始碼)Android原始碼
- iOS感測器:使用陀螺儀完成一個小球撞壁的小遊戲iOS遊戲
- 陀螺世界商城開發(介紹)
- css3實現的旋轉的陀螺效果CSSS3
- Unity3d 入門(一) 瞭解Unity3dUnity3D
- 實驗室儀器旋轉蒸發儀指南
- 家用儀器血壓測量儀電子方案
- Unity3d 初探Unity3D
- unity3d碰撞Unity3D
- unity3d sqliteUnity3DSQLite
- 甲醛檢測儀
- 裝置儀器儀表盤讀數識別系統
- unity3D進階Unity3D
- Unity3D入門Unity3D
- 幹掉Unity3DUnity3D
- 乙太網分析儀
- 自定義儀表盤
- 儀器使用手冊
- 儀器儀表行業智慧供應鏈系統解決方案行業
- Unity3D 單例模式Unity3D單例模式
- Unity3d的安裝Unity3D
- Unity3D 8叉樹Unity3D
- 【Unity3D】UI Toolkit容器Unity3DUI
- 【Unity3D】資源管理Unity3D
- 【Unity3D】常用快捷鍵Unity3D
- Unity3d 協程 StartCoroutineUnity3D
- unity3d攝像機Unity3D
- Unity3D遊戲實戰Unity3D遊戲
- Unity3d花屏處理Unity3D
- unity3d 事件說明Unity3D事件
- Unity3D 外掛大全Unity3D