Snaparazzi/Assets/Scripts/CameraManager.cs
2024-01-27 13:39:18 +01:00

50 lines
1.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class CameraManager : MonoBehaviour
{
public WebCamTexture webCamTexture;
public Button freezeButton;
public Button resumeButton;
// Start is called before the first frame update
void Start()
{
webCamTexture = new WebCamTexture();
WebcamResume();
}
// Update is called once per frame
void Update()
{
gameObject.GetComponent<RawImage>().texture = webCamTexture;
gameObject.GetComponent<RawImage>().material.mainTexture = webCamTexture;
}
public void WebcamResume()
{
webCamTexture.Play();
freezeButton.gameObject.SetActive(true);
resumeButton.gameObject.SetActive(false);
}
public void WebcamChange()
{
foreach (WebCamDevice webCamDevice in WebCamTexture.devices)
{
if (webCamTexture.deviceName != webCamDevice.name)
{
webCamTexture = new WebCamTexture(webCamDevice.name);
WebcamResume();
}
}
}
public void WebcamStop()
{
webCamTexture.Stop();
freezeButton.gameObject.SetActive(false);
resumeButton.gameObject.SetActive(true);
}
}