Перестаёт идти картинка с камеры unity
В моём приложении нужно использовать камеру (камеру с телефона), но когда я запускаю на телефоне, появляется запрос на доступ к камере. После того как нажимаю на кнопку согласия изображение не поступает. Чтобы оно поступало нужно перезапустить данную сцену.
Я использую этот скрипт:
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEngine.UI;
using ZXing;
using UnityEngine.SceneManagement;
using Newtonsoft.Json.Linq;
public class QRScanner : MonoBehaviour
{
WebCamTexture webcamTexture;
string QrCode = string.Empty;
void Start()
{
var renderer = GetComponent<RawImage>();
webcamTexture = new WebCamTexture(512, 512);
renderer.material.mainTexture = webcamTexture;
StartCoroutine(GetQRCode());
}
IEnumerator GetQRCode()
{
IBarcodeReader barCodeReader = new BarcodeReader();
webcamTexture.Play();
var snap = new Texture2D(webcamTexture.width, webcamTexture.height, TextureFormat.ARGB32, false);
while (string.IsNullOrEmpty(QrCode))
{
try
{
snap.SetPixels32(webcamTexture.GetPixels32());
var Result = barCodeReader.Decode(snap.GetRawTextureData(), webcamTexture.width, webcamTexture.height, RGBLuminanceSource.BitmapFormat.ARGB32);
if (Result != null)
{
QrCode = Result.Text;
if (!string.IsNullOrEmpty(QrCode))
{
Debug.Log("DECODED TEXT FROM QR: " + QrCode);
var json = JObject.Parse(QrCode);
var Monument = (string) json["Name"];
var City = (string) json["City"];
DataHolders.Monument = Monument;
DataHolders.City = City;
break;
}
}
}
catch (Exception ex) { Debug.LogWarning(ex.Message); }
yield return null;
}
webcamTexture.Stop();
SceneManager.LoadScene(3);
}
}
Как мне сделать, чтобы после получения доступа к камере, изображение пошло?