我从我复制的教程中获得了完全相同的代码,并且插入了网络摄像头并且可以工作。但是当我加载Unity游戏时(在Unity编辑器中)没有"没有设备连接"错误或不正确的脚本。我很困惑为什么它不起作用。
为什么不显示?
我的webCamScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class webCamScript : MonoBehaviour {
public GameObject webCameraPlane;
// 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 = true;
WebCamTexture webCameraTexture = new WebCamTexture ();
webCameraPlane.GetComponent<MeshRenderer> ().material.mainTexture = webCameraTexture;
webCameraTexture.Play ();
}
// Update is called once per frame
void Update () {
Quaternion cameraRotation = new Quaternion (Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.x, -Input.gyro.attitude.y);
this.transform.localRotation = cameraRotation;
}
}
我发现了问题,我在飞机上有一个自定义纹理,阻止了相机纹理的插入。
答案 0 :(得分:1)
我认为它与您将代码包装在if语句中以检查您是否在移动平台上运行这一事实有关。编辑器不会被归类为移动平台,因此该代码将被忽略