OpenWebCamaer.cs 715 B

123456789101112131415161718192021
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class OpenWebCamaer : MonoBehaviour
  5. {
  6. public string deviceName;
  7. WebCamTexture camTexture;
  8. // Use this for initialization
  9. IEnumerator Start() {
  10. yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
  11. if(Application.HasUserAuthorization(UserAuthorization.WebCam)) {
  12. WebCamDevice[] devices = WebCamTexture.devices;
  13. deviceName = devices[0].name;
  14. camTexture = new WebCamTexture(deviceName, 400, 300, 12);
  15. transform.GetComponent<MeshRenderer>().material.mainTexture = camTexture;
  16. camTexture.Play();
  17. }
  18. }
  19. }