Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Intro_Scritping/Roguelike2d/Assets/Script/Persistence.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
68 lines (56 sloc)
1.62 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
public class Persistence : MonoBehaviour { | |
public static Persistence Instance; | |
TextCore textCore; | |
public GameObject uiController = GameObject.Find("UIElementController"); | |
//public Canvas theUI; | |
public int health; | |
public int score; | |
public int cores; | |
public int power; | |
//Awake | |
void Awake() | |
{ | |
if (Instance == null) | |
{ | |
DontDestroyOnLoad(gameObject); | |
Instance = this; | |
} | |
else if (Instance != this) | |
{ | |
Destroy(gameObject); | |
} | |
} | |
// Use this for initialization | |
void Start () | |
{ | |
textCore = GameObject.Find("UIElementController").GetComponent<TextCore>(); | |
health = Persistence.Instance.health; | |
power = Persistence.Instance.power; | |
cores = Persistence.Instance.cores; | |
score = Persistence.Instance.score; | |
uiController = Persistence.Instance.uiController; | |
textCore = Persistence.Instance.textCore; | |
// theUI = Persistence.Instance.theUI; | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
health = textCore.health; | |
score = textCore.score; | |
power = textCore.power; | |
// cores = textCore.cores; | |
} | |
//Scene Transitions | |
public void SavePlayer() | |
{ | |
Persistence.Instance.health = health; | |
Persistence.Instance.score = score; | |
Persistence.Instance.cores = cores; | |
Persistence.Instance.power = power; | |
Persistence.Instance.uiController = uiController; | |
Persistence.Instance.textCore = textCore; | |
} | |
} |