Interacting with the user that logged in,How to work with the User that logged in
I am doing a simple school project where I have to build a game, register the user, log in, and save scores. Since it's a simple school project, I do not need a database like SQL, so I am saving all of the information into a text file (Users, Passwords, Scores). I made a Login, where if they enter the correct username and password, it initiates SceneManager.LoadScene(Game). That just brings me to the game, It does not save the person that logged in (I cant really explain it that well). ,
Answer by Larry-Dietz · Dec 05, 2019 at 04:33 AM
Before loading the "Game" scene, store the name of the logged in user with PlayerPrefs.
PlayerPrefs.SetString("LoggedInUser", name);
Then in your game scene, in the script that needs to know who is logged in, do this...
String LoggedInUser;
void Start()
{
LoggedInUser = PlayerPrefs.GetString("LoggedInUser");
}
You can save and read the score this way as well with SetInt and GetInt
Hope this helps, -Larry
Your answer
![](https://koobas.hobune.stream/wayback/20220612215717im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to stay connected on a website to send WWWForm? 1 Answer
How to stay logged in to forums and answers with Chrome? 1 Answer
MarshalDirectiveException: Cannot marshal type 'System.Collections.Generic.IEnumerable`1' 4 Answers
failed to login in unity 2020.1.6,cant login to unity 2020.1.6f 0 Answers
Grey Non Functioning Project Select/Log In Screen When Starting Unity 1 Answer