Hi Guys i have a problem setting the Playername in my Highscore Canvas. I am creating a game for Oculus Quest, with Unity 2019.1.14f1.
I have two diffrent Scenes, a Main Menu Scene and a Game Scene where i collect some Coins, they have a counter and everything works fine. I do have a Canvas where i put in my Name, bevor I start the Game. Then the scene switches to Game and turns back after 90 seconds in the main menu.
void GameOver()
{
if (timer <= 0)
{
if (PlayerPrefs.GetFloat("Score") < count)
{
PlayerPrefs.SetFloat("Score", count);
}
SceneManager.LoadScene("StartMenü");
}//Load a new scene
}
That is the part of the Code i attached to the Game Scene.
The Count gets Displayed in the Highscore Canvas text field, correctly.
Now I want to set the Playersname as well, when a new Highscore is Set.
But first of all the Name doesnt get displayed in the Textfield name.
Here is my Code in the Main Menue Scene , any suggestions how to solve that problem . Sorry for my bad englisch. My programming skills aren’t the best as well.
public class Highscore : MonoBehaviour
{
public Text highscoreTextfirst;
private int score;
public Text SpielerName;
public InputField iField;
private string SpielerNamestr;
// Start is called before the first frame update
private void Start()
{
score = (int) PlayerPrefs.GetFloat("Score");
highscoreTextfirst.text = score.ToString();
}
/* void SpielerN()
{
SpielerNamestr = iField.text;
PlayerPrefs.SetString("Spielername", SpielerNamestr);
SpielerNamestr = PlayerPrefs.GetString("Spielername");
SpielerName.text = SpielerNamestr;
}
*/
}