Snaparazzi/Assets/Scripts/CameraManager.cs

50 lines
1.2 KiB
C#
Raw Normal View History

2024-01-27 10:26:34 +00:00
using UnityEngine;
using UnityEngine.UI;
public class CameraManager : MonoBehaviour
{
2024-01-27 11:31:58 +00:00
public WebCamTexture webCamTexture;
2024-01-27 12:39:18 +00:00
public Button freezeButton;
public Button resumeButton;
2024-01-27 11:31:58 +00:00
2024-01-27 10:26:34 +00:00
// Start is called before the first frame update
2024-01-27 11:31:58 +00:00
void Start()
2024-01-27 10:26:34 +00:00
{
2024-01-27 12:39:18 +00:00
webCamTexture = new WebCamTexture();
WebcamResume();
2024-01-27 10:26:34 +00:00
}
// Update is called once per frame
void Update()
{
2024-01-27 11:31:58 +00:00
gameObject.GetComponent<RawImage>().texture = webCamTexture;
gameObject.GetComponent<RawImage>().material.mainTexture = webCamTexture;
2024-01-27 10:26:34 +00:00
}
2024-01-27 12:39:18 +00:00
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);
}
2024-01-27 10:26:34 +00:00
}