Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

Saving username using InputField and PlayerPrefs

$
0
0
I am trying to make PlayerPrefs save more than one registered user & display their logged in name on the game screen. I know how to do it for ONE player, but when I tried logging for a DIFFERENT player it only displayed the last registered users name, health, and gold amounts.
This is as far as I have gotten on the Registration script ( to keep track of my old one from the new one I named it "TestUserRegistration"). using UnityEngine; using UnityEngine.UI; public class TestUserRegistration : MonoBehaviour { public InputField username_textBox; public InputField password_textBox; public int numUsers; public string[] userNames; public void Start() { numUsers = PlayerPrefs.GetInt("NumUsers", 0); //how many registered users? userNames = new string[numUsers]; //create the user name array... for (var n=1; n <= numUsers; n++) { userNames[n] = PlayerPrefs.GetString("User" + n, ""); //and load them. } } public void Saving() { PlayerPrefs.SetString("User" + numUsers.ToString(), newUserName); numUsers++; PlayerPrefs.SetInt("NumUsers", numUsers); } } I am receiving an error in Visual Studio about this line of code in the Saving. PlayerPrefs.SetString("User" + numUsers.ToString(), newUserName); The error says, "The name 'newUserName' does not exist in the current context". I'm not understanding WHERE I would put a 'newUserName'. Could someone PLEASE help me?

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>