入れ子の状態でこルーチンを実行するとなぜかuserNameがNULLになります。
単体で実行される際はuserNameは問題なくアクセスできます。
エラー文は
getProfileの呼び出し(入れ子のコルーチンの呼び出し方)を調べていくつか試して見ましたが変わりません。
C#
1public IEnumerator Post(string email, string password) 2 { 3 var request = new UnityWebRequest("エンドポイント", "POST"); 4 request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); 5 yield return request.SendWebRequest(); 6 7 if (request.isNetworkError || request.isHttpError) 8 { 9 Debug.Log(request.error); 10 } 11 else 12 { 13 if (request.responseCode == 200) 14 { 15 Debug.Log("Form upload complete!"); 16 yield return getProfile.Post();// エラーになる 17 } 18 } 19 }
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using UnityEngine.Networking; 6 7public class GetProfile : MonoBehaviour 8{ 9 public Text userName; 10 11 public IEnumerator Post() 12 { 13 var request = new UnityWebRequest("エンドポイント", "GET"); 14 request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); 15 yield return request.SendWebRequest(); 16 17 if (request.isNetworkError || request.isHttpError) 18 { 19 Debug.Log(request.error); 20 } 21 else 22 { 23 Debug.Log("Form upload complete!"); 24 Debug.Log(request.downloadHandler.text); 25 26 string jsonCallback = request.downloadHandler.text; 27 GetProfileCallback jsonClass = JsonUtility.FromJson<GetProfileCallback>(jsonCallback); 28 29 // userNameがNULLになる 30 userName.text = jsonClass.name; 31 } 32 } 33} 34 35public class GetProfileCallback 36{ 37 public int id; 38 public string name; 39}
回答1件
あなたの回答
tips
プレビュー