Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# Dictionary contains key case insensitive 
Csharp :: c# combobox with text and value 
Csharp :: c# xml comment type reference 
Csharp :: c# make file not read only 
Csharp :: destroy gameobject with tag unity 
Csharp :: c# best way to loop and remove 
Csharp :: C# api get value from header 
Csharp :: c# convert string to uri 
Csharp :: why is called c# 
Csharp :: how to turn components on and off in unity through code 
Csharp :: unity list get item at index 
Csharp :: c# null conditional operator if statement 
Csharp :: unity rigidbody2d disable 
Csharp :: color32 unity 
Csharp :: unity singleton 
Csharp :: dynamically add rows to datagridview c# 
Csharp :: iframe set html content c# 
Csharp :: How can I display image from database in asp.net mvc. I created image table and image path as varchar 
Csharp :: math with c sharp 
Csharp :: c# linq select specific columns 
Csharp :: c# .equals vs == 
Csharp :: substring in c# 
Csharp :: unity dropdown 
Csharp :: csharp 3d array length 
Csharp :: How to create a Blazor server-side application in command prompt 
Csharp :: C# order a sorted list by key 
Csharp :: how to know pm or am C# 
Csharp :: stop playing audiosource 
Csharp :: c# tell if a class is a child or the class itself 
Csharp :: c# get executing file name 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =