51 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Webcam : MonoBehaviour
{
int camdex = 0;
WebCamTexture tex;
public RawImage display;
public Button nextSignButton;
void Awake(){
WebCamDevice device = WebCamTexture.devices[camdex];
tex = new WebCamTexture(device.name);
display.texture = tex;
tex.Play();
}
public void SwapCam(){
if(WebCamTexture.devices.Length > 0){
// Stop the old camera
display.texture = null;
tex.Stop();
tex = null;
// Find the new camera
camdex += 1;
camdex %= WebCamTexture.devices.Length;
// Start the new camera
WebCamDevice device = WebCamTexture.devices[camdex];
tex = new WebCamTexture(device.name);
display.texture = tex;
tex.Play();
}
}
// Scene changing is implemented here to avoid problems with webcam
public void loadScene(string sceneName) {
display.texture = null;
tex.Stop();
tex = null;
SceneManager.LoadScene(sceneName);
}
}