Skip to content

Instantly share code, notes, and snippets.

@WingmanAlex
Last active March 19, 2021 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WingmanAlex/9363be465483524f5f53f7e494244419 to your computer and use it in GitHub Desktop.
Save WingmanAlex/9363be465483524f5f53f7e494244419 to your computer and use it in GitHub Desktop.
Menu functionality for the game Fey Foray
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FadeIn : MonoBehaviour
{
public float fadeTime;
private Image blackScreen;
void Start()
{
blackScreen = GetComponent<Image>();
}
void Update()
{
blackScreen.CrossFadeAlpha(0f, fadeTime, false);
if(blackScreen.color.a == 0)
{
gameObject.SetActive(false);
}
}
}
using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
public class GameOver : MonoBehaviour
{
public string levelSelect;
public string mainMenu;
private LevelManager theLevelManager;
// Start is called before the first frame update
void Start()
{
theLevelManager = FindObjectOfType<LevelManager>();
}
// Update is called once per frame
void Update()
{
}
public void Restart()
{
PlayerPrefs.SetInt("coinCount", 0);
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
Time.timeScale = 1f;
}
public void QuitToMainMenu()
{
SceneManager.LoadScene(mainMenu);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class IntroScreen : MonoBehaviour
{
public string mainMenu;
[Tooltip("Insert Pause Screen")]
public GameObject theIntroScreen;
public float pausedTimeScale;
private LevelManager _theLevelManager;
private CharacterController _thePlayer;
void Start()
{
_theLevelManager = FindObjectOfType<LevelManager>();
_thePlayer = FindObjectOfType<CharacterController>();
Time.timeScale = 0;
_theLevelManager.levelMusic.Pause();
}
public void IntroScreenGo()
{
Time.timeScale = pausedTimeScale;
theIntroScreen.SetActive(true);
}
public void ResumeGame()
{
Time.timeScale = 1;
theIntroScreen.SetActive(false);
_theLevelManager.levelMusic.Play();
}
public void QuitToMainMenu()
{
Time.timeScale = 1f;
SceneManager.LoadScene(mainMenu);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public string firstLevel;
public string tutorialLevel;
public string[] levelNames;
public AudioSource mainMenuBGM;
public int startingLives;
// Start is called before the first frame update
void Start()
{
mainMenuBGM.Play();
}
// Update is called once per frame
void Update()
{
}
public void NewGame()
{
SceneManager.LoadScene(firstLevel);
Time.timeScale = 1f;
mainMenuBGM.Stop();
// for a continue function
for(int i = 0; i < levelNames.Length; i++)
{
PlayerPrefs.SetInt(levelNames[i], 0);
}
PlayerPrefs.SetInt("CoinCount", 0);
PlayerPrefs.SetInt("PlayerLives", startingLives);
}
public void Tutorial()
{
SceneManager.LoadScene(tutorialLevel);
mainMenuBGM.Stop();
}
public void Quit()
{
Application.Quit();
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class OptionsMenu : MonoBehaviour
{
public AudioMixer audioMixer;
public GameObject theOptionsMenu;
private void Update()
{
if (Input.GetButtonDown("pause"))
{
theOptionsMenu.SetActive(false);
}
}
public void MasterVolume(float Master)
{
audioMixer.SetFloat("Master", Mathf.Log10(Master) * 20);
}
public void MusicVolume(float Music)
{
audioMixer.SetFloat("Music", Mathf.Log10(Music) * 20);
}
public void SFXVolume(float SFX)
{
audioMixer.SetFloat("SFX", Mathf.Log10(SFX) * 20);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public string levelSelect;
public string mainMenu;
[Tooltip("Insert Pause Screen")]
public GameObject thePauseScreen;
public float pausedTimeScale;
private LevelManager _theLevelManager;
private CharacterController _thePlayer;
private PlayerSpawnUnit _theSpawner;
[SerializeField] private DifficultyInfo _difficultyInfo;
public GameObject Background;
// Start is called before the first frame update
void Start()
{
_theLevelManager = FindObjectOfType<LevelManager>();
_thePlayer = FindObjectOfType<CharacterController>();
_theSpawner = FindObjectOfType<PlayerSpawnUnit>();
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("pause"))
{
if(Time.timeScale == 0f)
{
ResumeGame();
}
else
{
PauseGame();
}
}
}
public void PauseGame()
{
Time.timeScale = pausedTimeScale;
thePauseScreen.SetActive(true);
Background.SetActive(true);
_theLevelManager.levelMusic.Pause();
_theSpawner.gameIsStopped = true;
}
public void ResumeGame()
{
Time.timeScale = 1;
_difficultyInfo.UpdateStats();
thePauseScreen.SetActive(false);
Background.SetActive(false);
_theSpawner.gameIsStopped = false;
_theLevelManager.levelMusic.Play();
}
public void QuitToMainMenu()
{
Time.timeScale = 1f;
SceneManager.LoadScene(mainMenu);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment