質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

2844閲覧

unityでUniTask使用時にエラーが発生する

mememe

総合スコア15

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2022/10/18 11:33

実現したいこと

下記参考サイトを元に「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}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

原因は不明ですが、UnityとUnity Hubを再インストールすると正常に使用することができるようになりました。

投稿2022/10/31 08:42

mememe

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問