Click button, Send data to text field in another scene

There are two scenes. Scene one has one button and one typable text field. Scene two has one button.

From Scene one, the button is used to go to scene two. In scene two, the button is pressed and sends back a variable, eg "A string", into the typable text field in scene one and then goes back to scene one, where the typable text field will now be displaying "A String".

How do I write the button in javascript to return it?


Use DontDestroyOnLoads to make an object (that holds your information, string, whatever) persistent during scene changes.

You can create an object in first scene, attach a sript to it and sen value of variable in this script. For example if you want to send user login script attachet to game object that will survife after second scene load should be:

// User login:

public var userLogin : String;

function Awake() {

// Do not destroy this game object:



Set userLogin in first scene and read in second.

Complete example can be found in my blog Listing 20 and 21.