- using UnityEngine;
- using System.Collections;
-
- public class CameraTest : MonoBehaviour
- {
- public WebCamTexture cameraTexture;
- public string cameraName="";
- private bool isPlay = false;
-
- void Start()
- {
- StartCoroutine(Test());
- }
-
-
- void Update()
- {
-
- }
-
- IEnumerator Test()
- {
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- cameraName = devices[0].name;
- cameraTexture = new WebCamTexture(cameraName, 400, 300, 15);
- cameraTexture.Play();
- isPlay = true;
- }
- }
-
- void OnGUI()
- {
- if (isPlay)
- {
- GUI.DrawTexture(new Rect(0, 0, 400, 300), cameraTexture, ScaleMode.ScaleToFit);
- }
- }
- }
posted @
2017-05-15 15:48
yfceshi
阅读(
4437)
评论()
编辑
收藏
举报