using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class SpellingBeeWebcam : 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; /// /// For later use /// public TextMeshProUGUI dynamic; /// /// Initialize the camera view /// void Awake() { WebCamDevice device = WebCamTexture.devices[camdex]; tex = new WebCamTexture(device.name); display.texture = tex; tex.Play(); } /// /// Switch to a different webcam /// 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); } }