Unity/PlayFab DisplayName ‘cadena’ no contiene una definición para ‘texto’ y ninguna extensión accesible para mí aceptando un primer argumento de tipo ‘cadena’
– UnityAssets3Free
buenas , me llamo juansito y hoy os traigo
esta unity pregunta
No puedo imprimir el nombre para mostrar almacenado en playfab en la configuración, la recepción del nombre de usuario está habilitada y el usuario existe, pero no puedo recuperarlo e imprimirlo, por lo que el script completa el usuario en el campo de texto. Siempre obtengo esto. error:
error CS1061: ‘cadena’ no contiene una definición para ‘texto’ y no se puede encontrar ningún método de extensión accesible ‘texto’ que acepte un primer argumento de tipo ‘cadena’ (¿falta una directiva de uso o una referencia de ensamblado?)
Cuando comento la línea que contiene el username.text
debug imprime el nombre de usuario correctamente en la consola.
public void PlayerData()
PlayFabClientAPI.GetAccountInfo(new GetAccountInfoRequest(
(result) =>
Debug.Log(username);
username.text = result.AccountInfo.Username;
,
(error) =>
Debug.LogError(error.GenerateErrorReport());
);
Código completo de PlayFabControler
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using PlayFab.Json;
using PlayFab.ProfilesModels;
using JsonObject = PlayFab.Json.JsonObject;
using System;
public class PlayFabController : MonoBehaviour
{
public static PlayFabController PFC;
private string userEmail;
private string userPassword;
private string username;
public GameObject loginPanel;
private void OnEnable()
if(PlayFabController.PFC == null)
PlayFabController.PFC = this;
else
if(PlayFabController.PFC != this)
Destroy(this.gameObject);
DontDestroyOnLoad(this.gameObject);
public void Start()
//Note: Setting title Id here can be skipped if you have set the value in Editor Extensions already.
if (string.IsNullOrEmpty(PlayFabSettings.TitleId))
PlayFabSettings.TitleId = "8741"; // Please change this value to your own titleId from PlayFab Game Manager
PlayerPrefs.DeleteAll();
//var request = new LoginWithCustomIDRequest CustomId = "GettingStartedGuide", CreateAccount = true ;
// PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);
if(PlayerPrefs.HasKey("EMAIL"))
userEmail = PlayerPrefs.GetString("EMAIL");
userPassword = PlayerPrefs.GetString("PASSWORD");
var request = new LoginWithEmailAddressRequest Email = userEmail, Password = userPassword ;
PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
#region Login
private void OnLoginSuccess(LoginResult result)
Debug.Log("Congratulations, you made your first successful API call!");
PlayerPrefs.SetString("EMAIL", userEmail);
PlayerPrefs.SetString("PASSWORD", userPassword);
loginPanel.SetActive(false);
GetStats();
// SceneManager.LoadScene("Menu");
private void OnRegisterSuccess(RegisterPlayFabUserResult result)
Debug.Log("Congratulations, you made your first successful API call!");
PlayerPrefs.SetString("EMAIL", userEmail);
PlayerPrefs.SetString("PASSWORD", userPassword);
GetStats();
loginPanel.SetActive(false);
private void OnLoginFailure(PlayFabError error)
var registerRequest = new RegisterPlayFabUserRequest Email = userEmail, Password = userPassword, Username = username ;
PlayFabClientAPI.RegisterPlayFabUser(registerRequest, OnRegisterSuccess, OnRegisterFailure);
private void OnRegisterFailure(PlayFabError error)
Debug.LogError(error.GenerateErrorReport());
public void GetUserEmail(string emailIn)
userEmail = emailIn;
public void GetUsername(string usernameIn)
username = usernameIn;
public void GetUserPassword(string passwordIn)
userPassword = passwordIn;
public void OnClickLogin()
var request = new LoginWithEmailAddressRequest Email = userEmail, Password = userPassword, ;
PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
#endregion Login
public int playerLevel;
public int gameLevel;
public int playerHealth;
public int playerDamage;
public int playerHighScore;
public int playerGolds;
public void PlayerData()
PlayFabClientAPI.GetAccountInfo(new GetAccountInfoRequest(),
(result) =>
Debug.Log(username);
//username.text = result.username;
username = result.AccountInfo.Username;
,
(error) =>
Debug.LogError(error.GenerateErrorReport());
);
#region PlayerStats
public void SetStats()
PlayFabClientAPI.UpdatePlayerStatistics(new UpdatePlayerStatisticsRequest
// request.Statistics is a list, so multiple StatisticUpdate objects can be defined if required.
Statistics = new List<StatisticUpdate>
new StatisticUpdate StatisticName = "PlayerLevel", Value = playerLevel ,
new StatisticUpdate StatisticName = "GameLevel", Value = gameLevel ,
new StatisticUpdate StatisticName = "PlayerHealth", Value = playerHealth ,
new StatisticUpdate StatisticName = "PlayerDamage", Value = playerDamage ,
new StatisticUpdate StatisticName = "PlayerHighScore", Value = playerHighScore ,
new StatisticUpdate StatisticName = "PlayerGolds", Value = playerGolds ,
,
result => Debug.Log("User statistics updated"); ,
error => Debug.LogError(error.GenerateErrorReport()); );
void GetStats()
PlayFabClientAPI.GetPlayerStatistics(
new GetPlayerStatisticsRequest(),
OnGetStats,
error => Debug.LogError(error.GenerateErrorReport())
);
void OnGetStats(GetPlayerStatisticsResult result)
Debug.Log("Received the following Statistics:");
foreach (var eachStat in result.Statistics)
Debug.Log("Statistic (" + eachStat.StatisticName + "): " + eachStat.Value);
switch(eachStat.StatisticName)
case "PlayerLevel":
playerLevel = eachStat.Value;
break;
case "GameLevel":
gameLevel = eachStat.Value;
break;
case "PlayerHealth":
playerHealth = eachStat.Value;
break;
case "PlayerDamage":
playerDamage = eachStat.Value;
break;
case "PlayerHighScore":
playerHighScore = eachStat.Value;
break;
case "PlayerGolds":
playerGolds = eachStat.Value;
break;
// Build the request object and access the API
public void StartCloudUpdatePlayerStats()
PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
FunctionName = "UpdatePlayerStats", // Arbitrary function name (must exist in your uploaded cloud.js file)
FunctionParameter = new Level = playerLevel, GameLevel = gameLevel, Health = playerHealth, Damage = playerDamage, highScore = playerHighScore, Golds = playerGolds ,
GeneratePlayStreamEvent = true, // Optional - Shows this event in PlayStream
, OnCloudUpdateStats, OnErrorShared);
// OnCloudHelloWorld defined in the next code block
private static void OnCloudUpdateStats(ExecuteCloudScriptResult result)
// CloudScript (Legacy) returns arbitrary results, so you have to evaluate them one step and one parameter at a time
JsonObject jsonResult = (JsonObject)result.FunctionResult;
object messageValue;
jsonResult.TryGetValue("messageValue", out messageValue); // note how "messageValue" directly corresponds to the JSON values set in CloudScript (Legacy)
Debug.Log((string)messageValue);
private static void OnErrorShared(PlayFabError error)
Debug.Log(error.GenerateErrorReport());
#endregion PlayerStats
}
0
nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias
sin mas,espero que te halla servido