From 488bf822e0b68c8fe03cf62a3559a04024123766 Mon Sep 17 00:00:00 2001 From: Matthew Kalahiki Date: Wed, 14 Apr 2021 21:29:08 -0500 Subject: [PATCH] Player shouldn't duplicate --- MuseumGame/Assets/Scripts/GameManager.cs | 236 +++++++++--------- .../UserSettings/EditorUserSettings.asset | 16 +- 2 files changed, 126 insertions(+), 126 deletions(-) diff --git a/MuseumGame/Assets/Scripts/GameManager.cs b/MuseumGame/Assets/Scripts/GameManager.cs index 4e584ee..0e44e69 100644 --- a/MuseumGame/Assets/Scripts/GameManager.cs +++ b/MuseumGame/Assets/Scripts/GameManager.cs @@ -1,119 +1,119 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using UnityEngine; -using UnityEngine.Assertions.Must; -using UnityEngine.SceneManagement; -using UnityEngine.UI; - -public class GameManager : MonoBehaviour -{ - public static GameManager Instance { get; private set; } - - public GameObject canvas; - public GameObject spriteToFade; - public GameObject events; - public GameObject player; - - public List obtainedPowerups = new List{ }; - public List powerupStatus = new List{ }; - - public string sceneToLoad = ""; - - void Awake() - { - if (Instance == null) - { - Instance = this; - DontDestroyOnLoad(gameObject); - DontDestroyOnLoad(canvas); - DontDestroyOnLoad(events); - DontDestroyOnLoad(player); - - } - else - { - Destroy(gameObject); - Destroy(canvas); - Destroy(events); - DontDestroyOnLoad(player); - } - } - // Start is called before the first frame update - void Start() - { - if (sceneToLoad != "") - { - LoadLevel(sceneToLoad, new Vector3(0, 0, 0)); - } - } - - // Update is called once per frame - void Update() - { - doGliderButtonCheck(); - } - - public void LoadLevel(string levelName, Vector3 whereTo) - { - StartCoroutine(LerpFunction(Color.black, 0.25f)); - StartCoroutine(LoadSceneAsync(levelName, whereTo)); - } - - IEnumerator LoadSceneAsync(string scene, Vector3 whereTo) - { - AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scene); - - // Wait until the asynchronous scene fully loads - while (!asyncLoad.isDone) - { - yield return null; - } - player.transform.position = whereTo; - } - - IEnumerator LerpFunction(Color endValue, float duration) - { - Image sprite = spriteToFade.GetComponent(); - spriteToFade.SetActive(true); - - float time = 0; - Color startValue = sprite.color; - - while (time < duration) - { - sprite.color = Color.Lerp(startValue, endValue, time / duration); - time += Time.deltaTime; - yield return null; - } - sprite.color = endValue; - spriteToFade.SetActive(false); - } - - private void doGliderButtonCheck() - { - if (obtainedPowerups.Contains(Powerup.Glider)) - { - if (Input.GetKeyDown("1")) - { - var index = Array.IndexOf(obtainedPowerups.ToArray(), Powerup.Glider); - var status = powerupStatus[index]; - if (!status) - { - player.GetComponent().IsGliding = true; - powerupStatus[index] = true; - } - else - { - player.GetComponent().IsGliding = false; - powerupStatus[index] = false; - } - } - } - } -} -// } -//} -//} - +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Assertions.Must; +using UnityEngine.SceneManagement; +using UnityEngine.UI; + +public class GameManager : MonoBehaviour +{ + public static GameManager Instance { get; private set; } + + public GameObject canvas; + public GameObject spriteToFade; + public GameObject events; + public GameObject player; + + public List obtainedPowerups = new List{ }; + public List powerupStatus = new List{ }; + + public string sceneToLoad = ""; + + void Awake() + { + if (Instance == null) + { + Instance = this; + DontDestroyOnLoad(gameObject); + DontDestroyOnLoad(canvas); + DontDestroyOnLoad(events); + DontDestroyOnLoad(player); + + } + else + { + Destroy(gameObject); + Destroy(canvas); + Destroy(events); + Destroy(player); + } + } + // Start is called before the first frame update + void Start() + { + if (sceneToLoad != "") + { + LoadLevel(sceneToLoad, new Vector3(0, 0, 0)); + } + } + + // Update is called once per frame + void Update() + { + doGliderButtonCheck(); + } + + public void LoadLevel(string levelName, Vector3 whereTo) + { + StartCoroutine(LerpFunction(Color.black, 0.25f)); + StartCoroutine(LoadSceneAsync(levelName, whereTo)); + } + + IEnumerator LoadSceneAsync(string scene, Vector3 whereTo) + { + AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scene); + + // Wait until the asynchronous scene fully loads + while (!asyncLoad.isDone) + { + yield return null; + } + player.transform.position = whereTo; + } + + IEnumerator LerpFunction(Color endValue, float duration) + { + Image sprite = spriteToFade.GetComponent(); + spriteToFade.SetActive(true); + + float time = 0; + Color startValue = sprite.color; + + while (time < duration) + { + sprite.color = Color.Lerp(startValue, endValue, time / duration); + time += Time.deltaTime; + yield return null; + } + sprite.color = endValue; + spriteToFade.SetActive(false); + } + + private void doGliderButtonCheck() + { + if (obtainedPowerups.Contains(Powerup.Glider)) + { + if (Input.GetKeyDown("1")) + { + var index = Array.IndexOf(obtainedPowerups.ToArray(), Powerup.Glider); + var status = powerupStatus[index]; + if (!status) + { + player.GetComponent().IsGliding = true; + powerupStatus[index] = true; + } + else + { + player.GetComponent().IsGliding = false; + powerupStatus[index] = false; + } + } + } + } +} +// } +//} +//} + diff --git a/MuseumGame/UserSettings/EditorUserSettings.asset b/MuseumGame/UserSettings/EditorUserSettings.asset index a3f3e85..d5e35ca 100644 --- a/MuseumGame/UserSettings/EditorUserSettings.asset +++ b/MuseumGame/UserSettings/EditorUserSettings.asset @@ -6,31 +6,31 @@ EditorUserSettings: serializedVersion: 4 m_ConfigSettings: RecentlyUsedScenePath-0: - value: 22424703114646680e0b0227036c72110203102f3b1c2323391a1e36ece57a2decee22f0 + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620d183eedd43b2fe7f578fce9332b25 flags: 0 RecentlyUsedScenePath-1: - value: 22424703114646680e0b0227036c6b1505032b292926237e38271427fb + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e52637edea78fce9332b25 flags: 0 RecentlyUsedScenePath-2: - value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1132eceb7414e7f133e5a92f31352d1b flags: 0 RecentlyUsedScenePath-3: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621d1224e7f27a2decee22f0 + value: 22424703114646680e0b0227036c72110203102f3b1c2323391a1e36ece57a2decee22f0 flags: 0 RecentlyUsedScenePath-4: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1132eceb7414e7f133e5a92f31352d1b + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620c1336eff9002dece933e5a92f31352d1b flags: 0 RecentlyUsedScenePath-5: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620c1336eff9002dece933e5a92f31352d1b + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a2362191c27ead43b1aedf425a7f234362820 flags: 0 RecentlyUsedScenePath-6: value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621b1226f6e50037d6e821ecf5742a323016f6 flags: 0 RecentlyUsedScenePath-7: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a2362191c27ead43b1aedf425a7f234362820 + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e5740be1e238eca92f31352d1b flags: 0 RecentlyUsedScenePath-8: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e5740be1e238eca92f31352d1b + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621d1224e7f27a2decee22f0 flags: 0 RecentlyUsedScenePath-9: value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d32f5ee7a2decee22f0