-
[3D] WebCam 구현Unity(유니티) 2022. 5. 4. 10:29
MainCamera를 포함한 GameObject에 아래 스크립트를 적용시켜주고 RawImage를 생성해서 참조
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class WebCam : MonoBehaviour { public RawImage display; //UI WebCamTexture camTexture; //웹캠 저장용 텍스처 private int currentIndex = 0; //디바이스상 카메라 찾기 위한 인덱스 // Start is called before the first frame update void Start() { WebCamDevice[] camDevices = WebCamTexture.devices; //웹캠을 찾기 위한 디바이스 셋팅 //string[] micDevices = Microphone.devices; for(int i = 0; i < camDevices.Length; i++) { Debug.Log(camDevices[i].name); } } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.X)) { if(camTexture != null) //초기화 { display.texture = null; camTexture.Stop(); camTexture = null; } WebCamDevice device = WebCamTexture.devices[currentIndex]; //웹캠 디바이스에 보여줌 camTexture = new WebCamTexture(device.name); // display.texture = camTexture; camTexture.Play(); } } }
해당 스크립트를 적용하면 참조한 RawImage에 웹캠 화면이 나오게 됨
* webcam 기능은 microsoft 도큐먼트를 참조
'Unity(유니티)' 카테고리의 다른 글
[3D] Recorder 사용하기 (영상 및 사진 파일로 저장, 녹음, 캡처) (0) 2022.05.04 [3D] 마이크 기능 구현(음성 채팅) (0) 2022.05.04 [3D] Raycast 활용하기(Ray, RaycastHit,Instantiate) (0) 2022.04.22 [JohnLemon 3D] 첫 번째 스크립트 작성하기(void Start) (0) 2022.04.20 [3D] 코루틴 사용하기 (0) 2022.04.20