Why does not DontDestroyOnLoad change when I change the scene?

1

I have gameObject with the script with all the information about the level, xp and etc for the game. It loads into the Loader scene, when I switch to the next scene, I do not want to lose this gameObject .

When I use DontDestroyOnLoad , instead of holding gameObject and loading it into other scenes, the name of the Loader scene changes pro to the gameObject name. And gameObject does not appear in other scenes.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PlayerStatsController : MonoBehaviour {

    public static PlayerStatsController instance;

    public int xpMultly = 1;
    public float xpFirstLevel = 100;
    public float difficultFactor = 1.5f;

    private float xpNextLevel;

    // Use this for initialization
    void Start () {
        instance = this;
        DontDestroyOnLoad(gameObject);
        SceneManager.LoadScene("GamePlay");

    }
}
    
asked by anonymous 16.06.2018 / 20:05

0 answers