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
- 移動端中的陀螺儀
- 對js陀螺儀的認知理解JS
- JavaScript 陀螺儀檢測裝置方向(重力感應)JavaScript
- iOS學習筆記34 加速計和陀螺儀iOS筆記
- 智慧掃地機器人陀螺儀構建地圖導航方案機器人地圖
- 【cartographer_ros】五: 釋出和訂閱陀螺儀Imu資訊ROS
- 陀螺世界商城開發(介紹)
- Unity3d 初探Unity3D
- unity3d碰撞Unity3D
- unity3d sqliteUnity3DSQLite
- unity3D進階Unity3D
- Unity3d FingerGestures 使用 例子Unity3D
- Unity3D 8叉樹Unity3D
- 【Unity3D】資源管理Unity3D
- 【Unity3D】UI Toolkit容器Unity3DUI
- Unity3d的安裝Unity3D
- Unity3D 單例模式Unity3D單例模式
- Unity3d 協程 StartCoroutineUnity3D
- Unity3D 快速參考Unity3D
- 【Unity3D】常用快捷鍵Unity3D
- 儀器儀表水銀價格多少錢
- Unity3d Android SDK接入解析(一)Unity3d 與 Android之間的互相呼叫Unity3DAndroid
- 家用儀器血壓測量儀電子方案
- 實驗室儀器旋轉蒸發儀指南
- unity3D AssetBundle載入方式Unity3D
- Unity3d主城玩家位置同步Unity3D
- Unity3D 透明物體ShaderUnity3D
- unity3d外掛之 DoTweenUnity3D
- Unity3D ARKit 參考文章Unity3D
- Unity3d 人物的跳躍Unity3D
- unity3d縮放物體Unity3D
- unity3d 讀取串列埠Unity3D串列埠
- Unity3D 基礎自學學習筆記(二) Unity3D 基礎控制元件Unity3D筆記控制元件
- 甲醛檢測儀
- Unity3D事件系統和EventSystemUnity3D事件
- Unity3D筆記五 快捷鍵Unity3D筆記
- Unity3D C#建立COM介面Unity3DC#
- Unity3D相關面試題Unity3D面試題