実現したいこと
下記参考サイトを元に「Unity Gaming Services」のロビーサービスの簡単なサンプルを作成したいです。
https://qiita.com/kai_yamamoto/items/fc9352aec8847bba0854
しかし、見出し「実装」の小見出し「サインイン」のソースの実行結果、UniTaskにてエラー(エラーメッセージ①参照)が発生します。
解決法など分かることがあればご教授いただきたいです。
エラーメッセージ①
Assets\Scripts\test.cs(19,19): error CS0246: The type or namespace name 'UniTask' could not be found (are you missing a using directive or an assembly reference?)
試したこと
下記参考サイトを元にUniTaskをPackageManagerでインストールし、「using Cysharp.Threading.Tasks;」をしたところエラー(エラーメッセージ②参照)が発生しました。
https://shibuya24.info/entry/unity-start-unitask#%E3%83%9D%E3%82%A4%E3%83%B3%E3%83%88%E2%91%A0:UniTask%E3%81%AE%E5%AE%9A%E7%BE%A9
エラーメッセージ②
Assets\Scripts\test.cs(13,9): error CS4033: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. Assets\Scripts\test.cs(14,19): error CS0103: The name 'UnityServices' does not exist in the current context Assets\Scripts\test.cs(16,9): error CS4033: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. Assets\Scripts\test.cs(24,19): error CS0103: The name 'AuthenticationService' does not exist in the current context Assets\Scripts\test.cs(27,16): error CS0246: The type or namespace name 'AuthenticationException' could not be found (are you missing a using directive or an assembly reference?) Assets\Scripts\test.cs(32,16): error CS0246: The type or namespace name 'RequestFailedException' could not be found (are you missing a using directive or an assembly reference?)
エラーメッセージ②を吐くソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using Cysharp.Threading.Tasks; 4using UnityEngine; 5 6 7public class test : MonoBehaviour 8{ 9 // Start is called before the first frame update 10 void Start() 11 { 12 // Unity Gaming Services の初期化処理 13 await UnityServices.InitializeAsync(); 14 Debug.Log(UnityServices.State); 15 16 await SignInAnonymouslyAsync(); 17 } 18 19 /// <summary>匿名サインインする処理</summary> 20 private async UniTask SignInAnonymouslyAsync() 21 { 22 try 23 { 24 await AuthenticationService.Instance.SignInAnonymouslyAsync(); 25 Debug.Log("匿名サインイン成功!"); 26 } 27 catch (AuthenticationException ex) 28 { 29 // 認証エラー時の例外 30 Debug.LogException(ex); 31 } 32 catch (RequestFailedException exception) 33 { 34 // リクエストエラー時の例外 35 Debug.LogException(exception); 36 } 37 } 38 39 // Update is called once per frame 40 void Update() 41 { 42 43 } 44}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。