You can use a static class for the persistence of data throughout the scenes. You can declare a UserData class, for example, and use static properties to store this data, for example:
class UserData{
// Nome de usuário do jogador.
public static string userName = "";
// Password do jogador.
public static string password = "";
}
It is not necessary to inherit MonoBehaviour in this case, nor to append the script to an object (in fact not inheriting MonoBehaviour ) nor can it be appended ).
So, at Scene1 you probably already have a script with a method that will be executed by clicking the button that switches to Scene2. Before loading Scene2 you can store your information, for example:
public void TrocaDeCena(){
// Armazena os dados do usuário.
UserData.userName = campoDeTextoUsername.text; // Aqui você já deve ter a referência do campo de texto onde o usuário digitou.
UserData.password = campoDeTextoPassword.text; // Aqui você já deve ter a referência do campo de texto onde o usuário digitou.
// Carrega a Cena2.
SceneManager.LoadScene("Cena2");
}
To retrieve the data stored in the static class in the next scene in the Start method of some script attached to the UI element that will display the information you will have code similar to the follow:
public void Start(){
// Aqui você já deve ter a referência do elemento text que exibirá o dado.
// Exibe o nome do usuário armazenado.
labelUserName.text = UserData.userName;
}
This is one of the simplest ways to traffic / persist data between scenes. How to get text field values and how to assign values in labels can change according to your version of Unity but the static class approach works from old versions.