DontDestroyOnLoad alternative?

Hi, I’m in the process of developing a game. In this game if the player dies, Time.timescale is set to 0 and a text appears saying "Click to restart game. Upon the mouse click, I have used the Appplication.LoadLevel (LevelName) command to reload the level. Now, my game features a portal. Upon entry, the Appplication.LoadLevel (LevelName) command is again used to load an alternate level. To avoid the portal erasing the main character, I entered the Application.DontDestroyOnLoad (gameObject) command in the Awake () function to keep the player in existence. This conflicts with the restart of the game when the player dies because it creates multiple copies. Is there a way to keep the player when it enters the portal, but destroy it on the restart of the level? (I want to avoid creating another player in the additional level). Any ideas? Maybe an alternative to DontDestroyOnLoad? Thanks in advance.

You could create an empty startup scene (that loads up for like 0.1 seconds when the game starts and then loads the other scenes, like the main menu for instance) with your player in it and the DontDestroyOnLoad command (and also all the other things you want to keep between loads but not instantiate multiple copies upon load).

This way you’ll never have to place your player entity gameobject in any of your scenes other than that startup scene. The player never gets destroyed by anyone, just teleport him to the new location.

You could do as raphu604 has said and create an initialisation scene where all persistent objects are created and set to DontDestroyOnLoad or as an alternative, you could create a singleton object to check if your player already exists before creating another like so:

using UnityEngine;
using System.Collections;

public class Singleton : MonoBehaviour {

    //The prefab for your player to be set in the inspector.
    public GameObject playerPrefab;

	// Use this for initialization
	void Start () {

        //if we don't find a player object in the scene already...
        if (!GameObject.FindGameObjectWithTag("YOUR_PLAYER_TAG"))
        {
            //Then instantiate one at a spawn position that you set...
            Instantiate(playerPrefab, YOUR_LEVEL_SPAWN_POSITION, Quaternion.identity);
        }

        //Otherwise, destroy this gameobject.
        else Destroy(gameObject);
	
	}	
}

Simply attach that script to an empty GameObject in your scene, set your playerPrefab, player tag and spawn position and you will only get 1 player object in each scene.