commit
3b8ad70d7c
@ -1,119 +1,119 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Assertions.Must;
|
using UnityEngine.Assertions.Must;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class GameManager : MonoBehaviour
|
public class GameManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static GameManager Instance { get; private set; }
|
public static GameManager Instance { get; private set; }
|
||||||
|
|
||||||
public GameObject canvas;
|
public GameObject canvas;
|
||||||
public GameObject spriteToFade;
|
public GameObject spriteToFade;
|
||||||
public GameObject events;
|
public GameObject events;
|
||||||
public GameObject player;
|
public GameObject player;
|
||||||
|
|
||||||
public List<Powerup> obtainedPowerups = new List<Powerup>{ };
|
public List<Powerup> obtainedPowerups = new List<Powerup>{ };
|
||||||
public List<bool> powerupStatus = new List<bool>{ };
|
public List<bool> powerupStatus = new List<bool>{ };
|
||||||
|
|
||||||
public string sceneToLoad = "";
|
public string sceneToLoad = "";
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
DontDestroyOnLoad(gameObject);
|
DontDestroyOnLoad(gameObject);
|
||||||
DontDestroyOnLoad(canvas);
|
DontDestroyOnLoad(canvas);
|
||||||
DontDestroyOnLoad(events);
|
DontDestroyOnLoad(events);
|
||||||
DontDestroyOnLoad(player);
|
DontDestroyOnLoad(player);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
Destroy(canvas);
|
Destroy(canvas);
|
||||||
Destroy(events);
|
Destroy(events);
|
||||||
DontDestroyOnLoad(player);
|
Destroy(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
if (sceneToLoad != "")
|
if (sceneToLoad != "")
|
||||||
{
|
{
|
||||||
LoadLevel(sceneToLoad, new Vector3(0, 0, 0));
|
LoadLevel(sceneToLoad, new Vector3(0, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
doGliderButtonCheck();
|
doGliderButtonCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadLevel(string levelName, Vector3 whereTo)
|
public void LoadLevel(string levelName, Vector3 whereTo)
|
||||||
{
|
{
|
||||||
StartCoroutine(LerpFunction(Color.black, 0.25f));
|
StartCoroutine(LerpFunction(Color.black, 0.25f));
|
||||||
StartCoroutine(LoadSceneAsync(levelName, whereTo));
|
StartCoroutine(LoadSceneAsync(levelName, whereTo));
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator LoadSceneAsync(string scene, Vector3 whereTo)
|
IEnumerator LoadSceneAsync(string scene, Vector3 whereTo)
|
||||||
{
|
{
|
||||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scene);
|
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scene);
|
||||||
|
|
||||||
// Wait until the asynchronous scene fully loads
|
// Wait until the asynchronous scene fully loads
|
||||||
while (!asyncLoad.isDone)
|
while (!asyncLoad.isDone)
|
||||||
{
|
{
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
player.transform.position = whereTo;
|
player.transform.position = whereTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator LerpFunction(Color endValue, float duration)
|
IEnumerator LerpFunction(Color endValue, float duration)
|
||||||
{
|
{
|
||||||
Image sprite = spriteToFade.GetComponent<Image>();
|
Image sprite = spriteToFade.GetComponent<Image>();
|
||||||
spriteToFade.SetActive(true);
|
spriteToFade.SetActive(true);
|
||||||
|
|
||||||
float time = 0;
|
float time = 0;
|
||||||
Color startValue = sprite.color;
|
Color startValue = sprite.color;
|
||||||
|
|
||||||
while (time < duration)
|
while (time < duration)
|
||||||
{
|
{
|
||||||
sprite.color = Color.Lerp(startValue, endValue, time / duration);
|
sprite.color = Color.Lerp(startValue, endValue, time / duration);
|
||||||
time += Time.deltaTime;
|
time += Time.deltaTime;
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
sprite.color = endValue;
|
sprite.color = endValue;
|
||||||
spriteToFade.SetActive(false);
|
spriteToFade.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doGliderButtonCheck()
|
private void doGliderButtonCheck()
|
||||||
{
|
{
|
||||||
if (obtainedPowerups.Contains(Powerup.Glider))
|
if (obtainedPowerups.Contains(Powerup.Glider))
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown("1"))
|
if (Input.GetKeyDown("1"))
|
||||||
{
|
{
|
||||||
var index = Array.IndexOf(obtainedPowerups.ToArray(), Powerup.Glider);
|
var index = Array.IndexOf(obtainedPowerups.ToArray(), Powerup.Glider);
|
||||||
var status = powerupStatus[index];
|
var status = powerupStatus[index];
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
player.GetComponent<Glider>().IsGliding = true;
|
player.GetComponent<Glider>().IsGliding = true;
|
||||||
powerupStatus[index] = true;
|
powerupStatus[index] = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player.GetComponent<Glider>().IsGliding = false;
|
player.GetComponent<Glider>().IsGliding = false;
|
||||||
powerupStatus[index] = false;
|
powerupStatus[index] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
Loading…
Reference in new issue