Using unity ,
So how can i check if display name exists?
What i am looking for is the first time the user signs enter his displayname but the next time the user tries to log in i want to say
Hey
if(Displayname == exists ){
then go to next page
}else{
let's add your DisplayName
}
my code so far:
using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using PlayFab.ClientModels; using UnityEngine.UI; using System; public class PlayFabAccount : MonoBehaviour { public InputField inputPlayerName; public GameObject accountPanel; public void UpdatePlayerName() { // Hole Text aus dem InputFeld string text = inputPlayerName.text; // Wenn das Textfeld nicht leer ist, dann Spielernamen aktualisieren if (text != null) { // Request erstellen var request = new UpdateUserTitleDisplayNameRequest(); request.DisplayName = text.ToString(); // API Anfrage PlayFabClientAPI.UpdateUserTitleDisplayName(request, OnPlayerNameResult, OnPlayFabError); } } public void ChangePanel() { if (accountPanel.activeSelf) { accountPanel.SetActive(false); } else { accountPanel.SetActive(true); } } private void OnPlayFabError(PlayFabError obj) { print("Error: " + obj.Error); } private void OnPlayerNameResult(UpdateUserTitleDisplayNameResult obj) { print("Spielername wurde aktualsiert: " + obj.DisplayName); } }
Answer by Jay Zuo · Oct 25, 2018 at 02:49 AM
Once the user has logged in, you can use GetPlayerProfile to retrieve the DisplayName. And if it's null or empty, then the display name is not set, you will need to update player name. For example:
PlayFabClientAPI.GetPlayerProfile(new GetPlayerProfileRequest { ProfileConstraints = new PlayerProfileViewConstraints { ShowDisplayName = true } }, result => { if (string.IsNullOrEmpty(result.PlayerProfile.DisplayName)) { UpdatePlayerName(); } else { //go to next page } }, error => { Debug.LogError(error.GenerateErrorReport()); });
i fixed in a different way i made it so that when someone register he had to register the username as well.
Answer by Nisan Bahar · Oct 16, 2019 at 11:58 AM
@manolhsplaths46 This still may not solve your issue since the user can just close the application before submitting the username, and then opening it again, leading the username to be null.