init
This commit is contained in:
commit
3b4c6e0ec6
506 changed files with 434142 additions and 0 deletions
88
Assets/Scripts/Menu/GameOverCanvas.cs
Normal file
88
Assets/Scripts/Menu/GameOverCanvas.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameOverCanvas : MonoBehaviour{
|
||||
|
||||
public int enemiesKilled;
|
||||
public int tilesEnabled;
|
||||
public float timeSurvived;
|
||||
int finalScore;
|
||||
|
||||
[Header("Win Canvas")]
|
||||
[SerializeField] GameObject winCanvas = default;
|
||||
[Space]
|
||||
[SerializeField] GameObject maxScoreText = default;
|
||||
[SerializeField] TextMeshProUGUI enemiesText = default;
|
||||
[SerializeField] TextMeshProUGUI tilesText = default;
|
||||
[SerializeField] TextMeshProUGUI scoreText = default;
|
||||
|
||||
[Header("Game Over Canvas")]
|
||||
[SerializeField] GameObject gameOverCanvas = default;
|
||||
[Space]
|
||||
[SerializeField] GameObject gameOverMaxScoreText = default;
|
||||
[SerializeField] TextMeshProUGUI gameOverEnemiesText = default;
|
||||
[SerializeField] TextMeshProUGUI gameOverTilesText = default;
|
||||
[SerializeField] TextMeshProUGUI gameOverScoreText = default;
|
||||
|
||||
public static GameOverCanvas instance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void Win(){
|
||||
PlayerPrefs.SetInt("Tutorial", 1);
|
||||
AudioManager.instance.Stop("Main");
|
||||
Time.timeScale = 0;
|
||||
winCanvas.SetActive(true);
|
||||
|
||||
enemiesText.text = enemiesKilled.ToString();
|
||||
tilesText.text = tilesEnabled.ToString();
|
||||
|
||||
if(enemiesKilled == 0){
|
||||
finalScore = Mathf.RoundToInt(2 * 8 * (tilesEnabled / 4) * (timeSurvived / 60));
|
||||
}else{
|
||||
finalScore = Mathf.RoundToInt(enemiesKilled * 8 * (tilesEnabled / 4) * (timeSurvived / 60));
|
||||
}
|
||||
scoreText.text = finalScore.ToString();
|
||||
|
||||
if (PlayerPrefs.HasKey("MaxScore")){
|
||||
if (PlayerPrefs.GetInt("MaxScore") >= finalScore){
|
||||
maxScoreText.SetActive(false);
|
||||
}else{
|
||||
PlayerPrefs.SetInt("MaxScore", finalScore);
|
||||
}
|
||||
}else{
|
||||
PlayerPrefs.SetInt("MaxScore", finalScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void Lose(){
|
||||
PlayerPrefs.SetInt("Tutorial", 1);
|
||||
Time.timeScale = 0;
|
||||
gameOverCanvas.SetActive(true);
|
||||
|
||||
gameOverEnemiesText.text = enemiesKilled.ToString();
|
||||
gameOverTilesText.text = tilesEnabled.ToString();
|
||||
|
||||
if (enemiesKilled == 0){
|
||||
finalScore = Mathf.RoundToInt(2 * 8 * (tilesEnabled / 4) * (timeSurvived / 60));
|
||||
}else{
|
||||
finalScore = Mathf.RoundToInt(enemiesKilled * 8 * (tilesEnabled / 4) * (timeSurvived / 60));
|
||||
}
|
||||
gameOverScoreText.text = finalScore.ToString();
|
||||
|
||||
if (PlayerPrefs.HasKey("MaxScore")){
|
||||
if (PlayerPrefs.GetInt("MaxScore") >= finalScore){
|
||||
gameOverMaxScoreText.SetActive(false);
|
||||
}else{
|
||||
PlayerPrefs.SetInt("MaxScore", finalScore);
|
||||
}
|
||||
}else{
|
||||
PlayerPrefs.SetInt("MaxScore", finalScore);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Menu/GameOverCanvas.cs.meta
Normal file
11
Assets/Scripts/Menu/GameOverCanvas.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 090f21fda4ea3c349a33fd2f5b5d5cf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
28
Assets/Scripts/Menu/LevelLoader.cs
Normal file
28
Assets/Scripts/Menu/LevelLoader.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LevelLoader : MonoBehaviour{
|
||||
|
||||
Animator anim;
|
||||
[SerializeField, Range(0f, 3f)] float fadeDuration = 1f;
|
||||
|
||||
public static LevelLoader instance;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void LoadScene(int scene){
|
||||
StartCoroutine(LoadLevel(scene));
|
||||
}
|
||||
|
||||
IEnumerator LoadLevel(int scene){
|
||||
anim.SetTrigger("Fade");
|
||||
yield return new WaitForSecondsRealtime(fadeDuration);
|
||||
SceneManager.LoadSceneAsync(scene);
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Menu/LevelLoader.cs.meta
Normal file
11
Assets/Scripts/Menu/LevelLoader.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fa9abfe5e6b6491418ec5cf5874c8960
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
80
Assets/Scripts/Menu/SettingsMenu.cs
Normal file
80
Assets/Scripts/Menu/SettingsMenu.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class SettingsMenu : MonoBehaviour{
|
||||
|
||||
[SerializeField] GameObject startButton;
|
||||
[SerializeField] GameObject[] mainMenu;
|
||||
|
||||
[Space]
|
||||
[SerializeField] TMP_Dropdown resolutionDropdown = default;
|
||||
Resolution[] resolutions;
|
||||
int currentResolutionIndex;
|
||||
|
||||
void Awake(){
|
||||
foreach(GameObject o in mainMenu){
|
||||
o.SetActive(false);
|
||||
}
|
||||
|
||||
if(resolutionDropdown != null){
|
||||
resolutions = Screen.resolutions.Select(resolution => new Resolution { width = resolution.width, height = resolution.height }).Distinct().ToArray();
|
||||
resolutionDropdown.ClearOptions();
|
||||
|
||||
List<string> options = new List<string>();
|
||||
for (int i = 0; i < resolutions.Length; i++){
|
||||
string option = resolutions[i].width + "x" + resolutions[i].height;
|
||||
options.Add(option);
|
||||
|
||||
if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height){
|
||||
currentResolutionIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
resolutions.Reverse();
|
||||
|
||||
resolutionDropdown.AddOptions(options);
|
||||
resolutionDropdown.value = currentResolutionIndex;
|
||||
resolutionDropdown.RefreshShownValue();
|
||||
}
|
||||
}
|
||||
|
||||
bool started;
|
||||
void Update(){
|
||||
if (Input.anyKeyDown && !started){
|
||||
AudioManager.instance.PlayOneShot("Start");
|
||||
AudioManager.instance.Play("Menu");
|
||||
startButton.SetActive(false);
|
||||
foreach(GameObject o in mainMenu){
|
||||
o.SetActive(true);
|
||||
}
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetQuality(int qualityIndex){
|
||||
QualitySettings.SetQualityLevel(qualityIndex);
|
||||
}
|
||||
|
||||
public void SetResolution(int resolutionIndex){
|
||||
Resolution resolution = resolutions[resolutionIndex];
|
||||
|
||||
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
|
||||
}
|
||||
|
||||
public void Play(){
|
||||
if (PlayerPrefs.HasKey("Tutorial")){
|
||||
LevelLoader.instance.LoadScene(2);
|
||||
}else{
|
||||
LevelLoader.instance.LoadScene(1);
|
||||
}
|
||||
AudioManager.instance.PlayOneShot("Play");
|
||||
}
|
||||
|
||||
public void Quit(){
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Menu/SettingsMenu.cs.meta
Normal file
11
Assets/Scripts/Menu/SettingsMenu.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 49bb5047f0f5ba845a7bc043bafa8fab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue