using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public RawImage display;
private WebCamTexture camTexture;
private bool isPlaying;
private AudioManager audioManager;
private CancellationTokenSource cts;
private void MakeCts()
{
cts?.Cancel();
cts?.Dispose();
cts = new CancellationTokenSource();
Debug.Log("CreateCts");
}
private void CancelCts()
{
cts?.Cancel();
cts?.Dispose();
cts = null;
Debug.Log("DeleteCts");
}
//////////////////////////////////////////////////////////////
///
//////////////////////////////////////////////////////////////
private void Awake()
{
Debug.Log("Awake");
instance = this;
MakeCts();
}
private void Start()
{
Debug.Log("Start");
audioManager = AudioManager.instance;
camTexture = new WebCamTexture(WebCamTexture.devices[0].name);
IdleState(cts.Token).Forget();
}
public void StartGame()
{
CancelCts();
isPlaying = true;
}
private async UniTaskVoid IdleState(CancellationToken ct)
{
while (!isPlaying)
{
LoadWebcam();
for (int i = 0; i < 5; i++)
{
audioManager.PlayCall();
await UniTask.Delay(4000, cancellationToken:ct);
}
StopWebcam();
await UniTask.Delay(20000, cancellationToken:ct);
}
}
private void LoadWebcam()
{
display.texture = camTexture;
camTexture.Play();
}
private void StopWebcam()
{
camTexture.Stop();
}
}
Awake UnityEngine.Debug:Log (object) GameManager:Awake () (at Assets/MyFolder/Scripts/GameManager.cs:43) CreateCts UnityEngine.Debug:Log (object) GameManager:MakeCts () (at Assets/MyFolder/Scripts/GameManager.cs:26) GameManager:Awake () (at Assets/MyFolder/Scripts/GameManager.cs:47) Start UnityEngine.Debug:Log (object) GameManager:Start () (at Assets/MyFolder/Scripts/GameManager.cs:52) NullReferenceException: Object reference not set .to an instance of an object GameManager.IdleState (System.Threading.CancellationToken ct) (at Assets/MyFolder/Scripts/GameManager.cs:70) UnityEngine.Debug:LogException(Exception) Cysharp.Threading.Tasks.UniTaskScheduler:PublishUnobservedTaskException(Exception) (at Assets/Plugins/UniTask/Runtime/UniTaskScheduler.cs:90) <IdleState>d__11:MoveNext() (at Assets/MyFolder/Scripts/GameManager.cs:65) Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskVoidMethodBuilder:Start(<IdleState>d__11&) (at Assets/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs:110) GameManager:IdleState(CancellationToken) GameManager:Start() (at Assets/MyFolder/Scripts/GameManager.cs:54)
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public RawImage display;
private WebCamTexture camTexture;
private bool isPlaying;
private AudioManager audioManager;
private CancellationTokenSource cts;
private void MakeCts()
{
cts?.Cancel();
cts?.Dispose();
cts = new CancellationTokenSource();
Debug.Log("CreateCts");
}
private void CancelCts()
{
cts?.Cancel();
cts?.Dispose();
cts = null;
Debug.Log("DeleteCts");
}
//////////////////////////////////////////////////////////////
///
//////////////////////////////////////////////////////////////
private void Awake()
{
Debug.Log("Awake");
instance = this;
MakeCts();
}
private void Start()
{
Debug.Log("Start");
audioManager = AudioManager.instance;
camTexture = new WebCamTexture(WebCamTexture.devices[0].name);
IdleState(cts.Token).Forget();
}
public void StartGame()
{
CancelCts();
isPlaying = true;
}
private async UniTaskVoid IdleState(CancellationToken ct)
{
while (!isPlaying)
{
LoadWebcam();
for (int i = 0; i < 5; i++)
{
audioManager.PlayCall();
await UniTask.Delay(4000, cancellationToken:ct);
}
StopWebcam();
await UniTask.Delay(20000, cancellationToken:ct);
}
}
private void LoadWebcam()
{
display.texture = camTexture;
camTexture.Play();
}
private void StopWebcam()
{
camTexture.Stop();
}
}
Awake UnityEngine.Debug:Log (object) GameManager:Awake () (at Assets/MyFolder/Scripts/GameManager.cs:43) CreateCts UnityEngine.Debug:Log (object) GameManager:MakeCts () (at Assets/MyFolder/Scripts/GameManager.cs:26) GameManager:Awake () (at Assets/MyFolder/Scripts/GameManager.cs:47) Start UnityEngine.Debug:Log (object) GameManager:Start () (at Assets/MyFolder/Scripts/GameManager.cs:52) NullReferenceException: Object reference not set .to an instance of an object GameManager.IdleState (System.Threading.CancellationToken ct) (at Assets/MyFolder/Scripts/GameManager.cs:70) UnityEngine.Debug:LogException(Exception) Cysharp.Threading.Tasks.UniTaskScheduler:PublishUnobservedTaskException(Exception) (at Assets/Plugins/UniTask/Runtime/UniTaskScheduler.cs:90) <IdleState>d__11:MoveNext() (at Assets/MyFolder/Scripts/GameManager.cs:65) Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskVoidMethodBuilder:Start(<IdleState>d__11&) (at Assets/Plugins/UniTask/Runtime/CompilerServices/AsyncUniTaskVoidMethodBuilder.cs:110) GameManager:IdleState(CancellationToken) GameManager:Start() (at Assets/MyFolder/Scripts/GameManager.cs:54)
이거보고 AudioManager 초기화 이슈인거 어케알았냐?
로그에 AudioManager관련된거 하나도 안나오는데 정확하네
그리고
t...t는 왜 금지어냐
광고로 올라오나..
ㅇㅇ ht..tp 땜에그럼
에러 로그 긁어서 물어보면 거의 대부분 해결해줌
gpt 점점 똑똑해지고 있음 - dc App
로그에 안찍혀있는데 맞출줄은 몰랏음 리얼 나는 안찍혀서 몰랐는데 ㅋㅋㅋㅋㅋ
t^_^t - dc App