In the following script, how can I store the puzzle advancement of the player as datas?…
- User
In the following script, how can I store the puzzle advancement of the player as datas? So the important variables related to the puzzle can be saved and load.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LovecraftianPuzzle : MonoBehaviour, IDataPersistence { public enum EldritchSymbols { Nyarlathotep, Azathoth, Cthulhu, ShubNiggurath, YogSothoth } public Transform[] symbolSlots; public GameObject[] eldritchSymbolPrefabs; public GameObject[] glyphsGameObject; public List glyphs; public List books; public GameObject portal; public Animator portalAnimator; public AudioSource gatewayAudio; public AudioClip placeSymbolSound; public AudioClip puzzleSolvedSound; public GameObject bookParticlePrefab; public GameObject shadowPeoplePrefab; private GameObject player; private AudioSource playerAudioSource; private InventoryManager InvManager; private AudioSource puzzleAudio; private FearSystem fearSystem; private QuestSystem questSystem;
private void Start() { player = GameObject.Find("Player"); playerAudioSource = player.GetComponent<AudioSource>(); puzzleAudio = GetComponent<AudioSource>(); InvManager = FindAnyObjectByType(typeof(InventoryManager)) as InventoryManager; fearSystem = FindAnyObjectByType(typeof(FearSystem)) as FearSystem; questSystem = FindAnyObjectByType(typeof(QuestSystem)) as QuestSystem; glyphs = new List<Glyphs> { new Glyphs { symbolType = EldritchSymbols.Nyarlathotep, symbolGlyph = glyphsGameObject[0]}, new Glyphs { symbolType = EldritchSymbols.Azathoth,symbolGlyph = glyphsGameObject[1]}, new Glyphs { symbolType = EldritchSymbols.Cthulhu, symbolGlyph = glyphsGameObject[2]}, new Glyphs { symbolType = EldritchSymbols.ShubNiggurath, symbolGlyph = glyphsGameObject[3]}, new Glyphs { symbolType = EldritchSymbols.YogSothoth, symbolGlyph = glyphsGameObject[4]} }; books = new List<Book> { new Book { title = "Invocations of The Cosmic Horror", symbolType = EldritchSymbols.Nyarlathotep, symbolPrefab = eldritchSymbolPrefabs[0] }, new Book { title = "Mark Of The Old Gods", symbolType = EldritchSymbols.Azathoth, symbolPrefab = eldritchSymbolPrefabs[1] }, new Book { title = "The House Of R'lyeh", symbolType = EldritchSymbols.Cthulhu, symbolPrefab = eldritchSymbolPrefabs[2] }, new Book { title = "The Shadow People", symbolType = EldritchSymbols.ShubNiggurath, symbolPrefab = eldritchSymbolPrefabs[3] }, new Book { title = "The Unknown and The Deep Void", symbolType = EldritchSymbols.YogSothoth, symbolPrefab = eldritchSymbolPrefabs[4] } }; } private List<EldritchSymbols> correctOrder = new List<EldritchSymbols>() { EldritchSymbols.Nyarlathotep, EldritchSymbols.Azathoth, EldritchSymbols.Cthulhu, EldritchSymbols.ShubNiggurath, EldritchSymbols.YogSothoth }; public List<EldritchSymbols> currentOrder = new List<EldritchSymbols>(); private Dictionary<EldritchSymbols, int> symbolToSlotIndex = new Dictionary<EldritchSymbols, int>(){ { EldritchSymbols.Nyarlathotep, 0 }, { EldritchSymbols.Azathoth, 1 }, { EldritchSymbols.Cthulhu, 2 }, { EldritchSymbols.ShubNiggurath, 3 }, { EldritchSymbols.YogSothoth, 4 } };
- Assistant