- Home /
InputField in a different scene to Text
Hey, sorry if there is a simple answer to my question, I'm a beginner in unity XD Im using 5.3. I have an InputField in my main menu scene, and in another scene I have a text gameobject which displays the InputField text.. I have added a javascript to my InputField (in my main menu scene):
var username : String;
var inputField : UnityEngine.UI.InputField;
var nameDisplay : UnityEngine.GUIText;
function NameInput () {
username = inputField.text;
nameDisplay.text = username;
inputField.enabled = false;
}
Since my InputField and my Text gameobject are in separate scenes, how do I assign this variable? Thanks, Sam ;) PS: What I'm trying to make is a username system similar to agar.io and slither.io where you enter your username in an inputfield in the main menu, and it appears above your player in the game scene.
Sorry, I didnt add that script to my InputField in my main menu scene, its in my main game scene where the text is displayed ;)
Hi. Please edit your question and remove the [Unsolved] bit. Unity Answers is different from most forums, it functions similar to stackoverflow.
It is obvious the question is unsolved because you haven't accepted any answer yet. When you (or a moderator) accept an answer, the question appears with a green background next to it. Then additionally it can be closed so it is 100% obvious the question has been processed accordingly.
Answer by RealMTG · May 21, 2016 at 11:44 AM
I would use PlayerPrefs and more specifically, PlayerPrefs.SetString. So in your first scene before you enter the next scene you can save your name using something like...
PlayerPrefs.SetString("Username", inputField.text);
...where "inputField" is your username field. Then in the next scene, you can load the username variable and apply it to your text object by doing something like...
playerName.text = PlayerPrefs.GetString("Username");
...where playerName is your text object.
Hope this helped you! :)
Thanks this helps a lot, but where do I put these lines? I have not got any scripts assigned to my InputField in my main menu, only one in the main game on the text display, which is the code in my original post! Thanks ;)
The first one you can put right before you change scene. The last one you can put when you've created your player.
Its own script, or inside another one? Sorry, kinda a noob XD