Skip to content
Snippets Groups Projects
Commit 32f3563c authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Add Data.cs

parent 2d7fefb0
Branches
No related tags found
No related merge requests found
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Data : MonoBehaviour
{
public bool debug = true;
public static Data instance;
public string currentScene;
public List<string> PlayedList = new List<string>();
public List<string> VisitedScenes = new List<string>();
void Awake() {
if(instance == null) {
instance = this;
DontDestroyOnLoad(this.gameObject);
}
if (currentScene == "") {
currentScene = SceneManager.GetActiveScene().name;
RegisterScene(currentScene);
}
Debug.LogFormat("Current Scene after Awake is: {0}", currentScene);
}
public void RegisterSound(string name) {
Debug.LogFormat("Registering Sound as Played: {0}", name);
PlayedList.Add(name);
}
public bool PlayedSound(string name) {
return PlayedList.Contains(name);
}
public void UpdateScene(string SceneName){
// Unloading old scene
SceneManager.UnloadSceneAsync(currentScene);
Debug.LogFormat("Scene Switch from {0} to {1} completed", currentScene, SceneName);
// Updating new scene
currentScene = SceneName;
RegisterScene(SceneName);
}
public void RegisterScene(string name) {
if (!WasThereBefore(name)) {
VisitedScenes.Add(name);
Debug.LogFormat("Registering Scene as Visited: {0}", name);
}
}
// Return true if the scene was visited before
public bool WasThereBefore(string name) {
return VisitedScenes.Contains(name);
}
// Return true if the current scene was visited before
public bool WasHereBefore() {
return VisitedScenes.Contains(currentScene);
}
}
......@@ -111,7 +111,7 @@ public class SceneSwitch : MonoBehaviour
yield return null;
}
// Data.instance.UpdateScene(SceneName);
Data.instance.UpdateScene(SceneName);
}
}
......@@ -2,7 +2,12 @@
Allows you to switch the active Scene when a Triggervolume is entered, exited or when you stay in a trigger volume for long enough
1. Copy the Script `Assets/SceneSwitch.cs` to your assets folder
2. Drag it onto the Trigger Volume
1. Copy the Script `Assets/SceneSwitch.cs` and `Assets/Data.cs` to your assets folder
2. Drag `SceneSwitch.cs` onto the Trigger Volume
3. Enter a Scene Name (for the target Scene)
4. Select a mode (On Enter, On Exit, Countdown)
5. Drag `Data.cs` onto an empty Gameobject called "Data"
Data.cs can be used to transfer Data between scenes
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment