34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class gyroscope : MonoBehaviour {
|
|
|
|
//PC上模拟陀螺仪的输入值
|
|
public Vector3 debugGro = new Vector3(0f,0f,0f);
|
|
public bool isDebug = false;
|
|
//用来定位的模型
|
|
public GameObject model;
|
|
// Use this for initialization
|
|
void Start () {
|
|
//陀螺仪的设置
|
|
Input.gyro.enabled = true;
|
|
Input.compensateSensors = true;
|
|
Input.gyro.updateInterval = 0.01f;
|
|
}
|
|
// Update is called once per frame
|
|
void Update () {
|
|
//根据陀螺仪返回的数据设置Camera的姿态。
|
|
gameObject.transform.localRotation = (isDebug ? Quaternion.Euler (debugGro) : Input.gyro.attitude)* new Quaternion(0,0,1,0);
|
|
// //如果第一次启动就对定位的模型进行赋值,设置其在屏幕的中央。(此处为我的项目需要用到的,可以忽略。)
|
|
// if(model.GetComponent<ModelPos>().enabled == false){
|
|
// StartCoroutine (ScriptTrue ());
|
|
}
|
|
|
|
}
|
|
// IEnumerator ScriptTrue(){
|
|
// yield return new WaitForSeconds (0.3f);
|
|
// model.GetComponent<ModelPos> ().enabled = true;
|
|
// }
|
|
|
|
|