Unity6でゲームを作成しています。
UniTaskのキャンセルがわかりません。
オブジェクトに"CountDownScr"というスクリプトを付けました。
UniTaskを使い1秒毎にカウントダウンしていくのですが、右クリックをしたらオブジェクトは非表示になりカウントダウンをキャンセルしてほしいです。
そして左クリックしたらまたカウントダウンしてほしいです。
そして、右クリックしたら
OperationCanceledException: The operation was canceled.
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1[TStateMachine].GetResult (System.Int16 token) (at ./Library/PackageCache/com.cysharp.unitask/Runtime/CompilerServices/StateMachineRunner.cs:218)
というエラーが出てしまいました。
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
public class CountDownScr : MonoBehaviour
{
CancellationTokenSource cts;
async void Start() { cts = new CancellationTokenSource(); await CountDown(cts.Token); } async UniTask CountDown(CancellationToken token) { print("3"); await UniTask.Delay(TimeSpan.FromSeconds(1), cancellationToken: token); print("2"); await UniTask.Delay(TimeSpan.FromSeconds(1), cancellationToken: token); print("1"); await UniTask.Delay(TimeSpan.FromSeconds(1), cancellationToken: token); print("0"); } void Update() { if (Input.GetMouseButtonDown(1)) { gameObject.SetActive(false); print("R"); cts.Cancel(); } if (Input.GetMouseButtonDown(0)) { Start(); print("L"); } }
}
よろしくお願いします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。