From 25d4ff6e925c090c8c9884fdfd5ea8ab33c6c953 Mon Sep 17 00:00:00 2001 From: Fangh Date: Sun, 28 Jan 2024 21:53:27 +0100 Subject: [PATCH] fix(cameramanager): webcamtexture sometime failed to initialize --- Assets/Scripts/CameraManager.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/CameraManager.cs b/Assets/Scripts/CameraManager.cs index 511ec47..e1efc06 100644 --- a/Assets/Scripts/CameraManager.cs +++ b/Assets/Scripts/CameraManager.cs @@ -4,18 +4,17 @@ public class CameraManager : MonoBehaviour { - public WebCamTexture wTexture; public WebCamDevice wDevice; public Button freezeButton; public Button resumeButton; public RawImage photoBox; private Texture2D photo; private int numberOfWebcams; + private WebCamTexture wTexture; // Start is called before the first frame update void OnEnable() { - wTexture = new WebCamTexture(wDevice.name); WebcamResume(); } @@ -45,6 +44,9 @@ void Update() public void WebcamResume() { + if (wTexture == null) + wTexture = new WebCamTexture(wDevice.name); + wTexture.Play(); photo = null; freezeButton.gameObject.SetActive(true);