Advertisement
LeeMace

Main Manager for Data Persistence between Scenes

Jan 9th, 2023 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. //main manager for data persistnece between scenes
  6.  
  7. public class MainManager : MonoBehaviour
  8. {
  9.     public static MainManager Instance;
  10.  
  11. //variable for picking the colour of vehicles in the lesson
  12.     public Color TeamColor;
  13.  
  14.     private void Awake()
  15.     {
  16.     //this is to destroy the second main manager which appears after returning to the original scene
  17.         if (Instance != null)
  18.         {
  19.             Destroy(gameObject);
  20.             return; //i forgot to add this line and only saw the mistake after reviewing for the next project
  21.         }
  22.  
  23.         Instance = this;
  24.         DontDestroyOnLoad(gameObject);
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement