Code analysis
This commit is contained in:
39
Assets/Common/Scripts/WebcamAuthorization.cs
Normal file
39
Assets/Common/Scripts/WebcamAuthorization.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Authorize and check for available webcam(s)
|
||||
/// </summary>
|
||||
public class WebcamAuthorization : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// UI Reference to the text object to display an error message
|
||||
/// </summary>
|
||||
public TMP_Text errorText;
|
||||
|
||||
/// <summary>
|
||||
/// Request authorization and check whether at least 1 webcam is available
|
||||
/// </summary>
|
||||
/// <returns>IEnumerator object</returns>
|
||||
IEnumerator Start()
|
||||
{
|
||||
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
|
||||
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
|
||||
{
|
||||
if (0 < WebCamTexture.devices.Length)
|
||||
{
|
||||
SceneManager.LoadScene("Common/Scenes/StartScreen");
|
||||
}
|
||||
else
|
||||
{
|
||||
errorText.text = "Zorg ervoor dat je webcam correct is aangesloten!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorText.text = "Zorg ervoor dat deze applicatie toegang heeft tot je webcam!";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user