How to pass a string from one scene to another ?

I’ve 2 scenes one for the menu and the other is the game scene.
I’ve created a script for the names (player - name)
but when I enter the name of the player and start the game, the name doesn’t appear on the other scene (game scene)

Look up how a GameManager works, generally speaking.

Here is an ULTRA-simple static solution to a GameManager:

OR for a more-complex “lives as a MonoBehaviour” solution…

Simple Singleton (UnitySingleton):

Some super-simple Singleton examples to take and modify:

Simple Unity3D Singleton (no predefined data):

Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:

These are pure-code solutions, do not put anything into any scene, just access it via .Instance!

If it is a GameManager, when the game is over, make a function in that singleton that Destroys itself so the next time you access it you get a fresh one, something like:

public void DestroyThyself()
{
   Destroy(gameObject);
   Instance = null;    // because destroy doesn't happen until end of frame
}
2 Likes

Thanks for your time and Help.

1 Like

If you just want to pass a single string, I’d just use a static variable.

public static string IAintAfraidOfNoSceneChange = "";

Then you just set it in the first scene, and you can access it in the second scene. With static variables, you access them as part of the class itself, rather than an instance of the class. So if your script is named something like StringManager, you can access that variable from any script as StringManager.IAintAfraidOfNoSceneChange

2 Likes