Files
unity-application/Assets/SpellingBee/Scripts/SpellingBeeWebcam.cs
Dries Van Schuylenbergh 26f3322e4e Add formatting rules
2023-03-10 09:21:11 +00:00

77 lines
1.8 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SpellingBeeWebcam : MonoBehaviour
{
int camdex = 0;
WebCamTexture tex;
public RawImage display;
public TextMeshProUGUI dynamic;
void Awake()
{
//popup.SetActive(false);
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);
}
/*
public void Show_feedback(){
if(popup.activeSelf){
dynamic.text = "";
popup.SetActive(false);
return;
}
double index = UnityEngine.Random.value;
if(index < 0.5){
dynamic.text = "Poor";
}
else if(index > 0.8){
dynamic.text = "Excellent";
}
else{
dynamic.text = "Good";
}
popup.SetActive(true);
}
*/
}