How to pass two player names from one scene to next scene?

I am a beginner and i am working on a game called TicTacToe. So After splash screen there comes a screen where 2 players need to enter there names for X & O respectively. Now after entering when player clicks on start game , then it loads next scene where game board is provided to play…there i need to show those player names at the top which were entered in previous scene. Please Help me… I am stuck here

There are several ways you could do this.

You could save their names into player prefs: Unity - Scripting API: PlayerPrefs.SetString

Or you could have a “game manager” class which you mark as DontDestroyOnLoad(…) which stores data about the game state. It won’t get destroyed when you change scenes, so you can put data in there from the menu and then access it from the game.

As a starting point, maybe something like this:

public class GameManager : MonoBehaviour 
{
    public string Player1Name;
    public string Player2Name;

    void Awake() 
    {
        DontDestroyOnLoad(transform.gameObject);
    }
}