using UnityEngine; using UnityEngine.UI; /// /// Class to manage all webcam stuff inside the SpellingBee minigame /// public class JustSignWebcam : MonoBehaviour { /// /// Index of the current camera /// int camdex = 0; /// /// Texture to paste on the display /// WebCamTexture tex; /// /// Display for the video feed /// public RawImage display; /// /// Setup the webcam correctly /// void Awake() { WebCamDevice device = WebCamTexture.devices[camdex]; tex = new WebCamTexture(device.name); display.texture = tex; tex.Play(); } /// /// Swap webcam by cycling through the `WebCamTexture.devices` list /// 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 GotoThemeSelection() { display.texture = null; tex.Stop(); tex = null; SystemController.GetInstance().BackToPreviousScene(); } }