Gyro无法在Android设备上运行Unity3D项目

时间:2018-05-24 20:21:21

标签: c# android unity3d

我正在做这个教程https://youtu.be/T6bd_MQ2ass它适用于iPhone。 我一步一步地按照教程,我无法弄清楚这里似乎是什么问题。

手机的陀螺仪很好我测试了它(Moto G5)我的PC上没有网络摄像头,所以无法说出它在相机中的样子,也许这就是为什么图像如此伸展。我现在还不太关心。如果你能帮助我,那也很棒。

这是主摄像头的代码

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class webCamScript : MonoBehaviour {



public GameObject webCameraPlane; 
  public Button fireButton;


  // Use this for initialization
  void Start () {

if (Application.isMobilePlatform) {
  GameObject cameraParent = new GameObject ("camParent");
  cameraParent.transform.position = this.transform.position;
  this.transform.parent = cameraParent.transform;
  cameraParent.transform.Rotate (Vector3.right, 90);
}

Input.gyro.enabled = false;
Input.gyro.enabled = true;

fireButton.onClick.AddListener (OnButtonDown);


WebCamTexture webCameraTexture = new WebCamTexture();
webCameraPlane.GetComponent<MeshRenderer>().material.mainTexture = webCameraTexture;
webCameraTexture.Play();




}


  void OnButtonDown(){

GameObject bullet = Instantiate(Resources.Load("bullet", typeof(GameObject))) as GameObject;
Rigidbody rb = bullet.GetComponent<Rigidbody>();
bullet.transform.rotation = Camera.main.transform.rotation;
bullet.transform.position = Camera.main.transform.position;
rb.AddForce(Camera.main.transform.forward * 1000f);
Destroy (bullet, 3);

GetComponent<AudioSource> ().Play ();




 }



  // Update is called once per frame
  void Update () {

Quaternion cameraRotation = new Quaternion (-Input.gyro.attitude.x, -Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
this.transform.localRotation = cameraRotation;


  }
}

我正在做这个教程https://youtu.be/T6bd_MQ2ass它适用于iPhone。 我一步一步地按照教程,我无法弄清楚这里似乎是什么问题。

This is how it should look like

This is how it is looking (there is no gyro control here.)

0 个答案:

没有答案