Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Google Profile Picture Greyed out

Discussion in 'Scripting' started by ShakeTheAi, Jun 11, 2024.

  1. ShakeTheAi

    ShakeTheAi

    Joined:
    Dec 12, 2018
    Posts:
    19
    Hello,

    I'm using this code to get the profile picture and name from google, but the image becoming grey after signing in.

    here's the code, i'm not a programmer but i do have basic code understanding. can you guys look at it


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using GooglePlayGames;
    6. using GooglePlayGames.BasicApi;
    7. using TMPro;
    8.  
    9. public class PlayGamesManager : MonoBehaviour
    10. {
    11.     public Text DetailText;
    12.     public Image img;
    13.     public GameObject hidesign;
    14.     void Start()
    15.     {
    16.         Signin();
    17.         StartCoroutine(localImage());
    18.     }
    19.  
    20.     public void Signin()
    21.     {
    22.         PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
    23.  
    24.     }
    25.     internal void ProcessAuthentication(SignInStatus status)
    26.     {
    27.         if (status == SignInStatus.Success)
    28.         {
    29.             // Continue with Play Games Services
    30.             string name = PlayGamesPlatform.Instance.GetUserDisplayName();
    31.             string id = PlayGamesPlatform.Instance.GetUserId();
    32.             string ImgUrl = PlayGamesPlatform.Instance.GetUserImageUrl();
    33.  
    34.             DetailText.text = "Welcome \n " + name;
    35.             hidesign.SetActive(false);
    36.  
    37.         }
    38.         else
    39.         {
    40.             DetailText.text = "Please Login";
    41.             hidesign.SetActive(true);
    42.             // Disable your integration with Play Games Services or show a login button
    43.             // to ask users to sign-in. Clicking it should call
    44.             // PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
    45.         }
    46.     }
    47.  
    48.     IEnumerator localImage()
    49.     {
    50.         Texture2D tex;
    51.         while (Social.localUser.image == null)
    52.         {
    53.             Debug.Log("Google image not found");
    54.             yield return null;
    55.         }
    56.         Debug.Log("Google image found");
    57.         tex = Social.localUser.image;
    58.         img.sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0f,0f));
    59.     }
    60. }
    61.