private void Awake()
 {
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
Example #2
0
    public Vector3 playerPos;              //A Vector3 made of the previous values, reconstructed on load since Vector3's can't be serialized.

    void Awake()                           //The awake function checks to see if control has been assigned. If it hasn't it sets the current instance of the script as control. If control already exists, it is destroyed. This makes sure that there is only one saveloadcontrol script active in any given scene.
    {
        if (control == null)
        {
            DontDestroyOnLoad(gameObject);
            control = this;
        }
        else if (control != this)
        {
            Destroy(gameObject);
        }
        player = GameObject.FindGameObjectWithTag("Player");         //Assigns the FPSController prefab.
    }