unity switch to scene and transfer data

using UnityEngine;

/// <summary>Manages data for persistance between levels.</summary>
public class DataManager : MonoBehaviour 
{
    /// <summary>Static reference to the instance of our DataManager</summary>
    public static DataManager instance;

    /// <summary>The player's current score.</summary>
    public int score;
    /// <summary>The player's remaining health.</summary>
    public int health;
    /// <summary>The player's remaining lives.</summary>
    public int lives;

    /// <summary>Awake is called when the script instance is being loaded.</summary>
    void Awake()
    {
        // If the instance reference has not been set, yet, 
        if (instance == null)
        {
            // Set this instance as the instance reference.
            instance = this;
        }
        else if(instance != this)
        {
            // If the instance reference has already been set, and this is not the
            // the instance reference, destroy this game object.
            Destroy(gameObject);
        }

        // Do not destroy this object, when we load a new scene.
        DontDestroyOnLoad(gameObject);
    }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
unity save settings between scenes save values bbetween scene unity unity save between scenes unity make script stay between scenes unity data between scenes unity how to keep information for next scene unity persist object across scenes unity passing variables between scenes give data to anothere scene unityy best way to save data through scene change mirror transfer data between scenes unity how to share values over scenes unity unity load scene from database unity persist between scenes unity keep variables between scenes unity pass variable from one scene to another pass data from one scene to another unity how to pass data from one scene to another scene in unity save info from scene to another unity pass data to loaded scene unity transfer data between scenes how to keep variables across scenes unity pass variables through scenes unity unity pass information between scenes unity keep info through scencs send data between scenes unity unity transfer data between scenes how to transfer data through scenes unity keep values between scenes how to store text between scenes unity Unity best way to comunicate data between scenes how to start a scene but keep all variables the same unity c# unity persistent object between scenes how to transfer data between scenes in unity how to Save objects between scenes in Unity how to transfer data to next scne in unity bring data from one scene to the next unity save global variables across scenes howtoo store information across scenese in unity scene data unity how to get data from close scene unity storte data over all scenes unity unity pass data between scenes
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source