-1

I Have 2 scripts. In one, you have a function where you can sign in. It needs a username and I want that username on a TMP Text that is located on the main menu scene.

    public string Username;

It IS a public string. Other script:

    public TextMeshProUGUI playerName;

And that is the TMP Text on which the player's username should be displayed.

I know how I could pass variables between scripts, but I don't know how to pass them through whole scenes.

Kinda rushed sorry.

GraniteSOS
  • 49
  • 2
  • 10
  • 2
    Does this answer your question? [How to pass data between scenes in Unity](https://stackoverflow.com/questions/32306704/how-to-pass-data-between-scenes-in-unity) – Remy Aug 20 '20 at 10:42
  • DontDestroyOnLoad only works for root GO's or components on root GO's. – GraniteSOS Aug 20 '20 at 10:54

2 Answers2

0

You can try using PlayerPrefs.

Set players name on PlayerPrefs after login:

PlayerPrefs.SetString("Name", m_PlayerName);

Later load it on another scene from PlayerPrefs:

m_PlayerName = PlayerPrefs.GetString("Name", "No Name");
Yern
  • 333
  • 1
  • 10
0

And if you would like to keep it persist between scenes PlayerPrefs would work as well.

fastbyte22
  • 56
  • 6