i3e-asg2/Assets/Scripts/GameManager.cs
Sc0rch-thinks b0364a3dbf final commit yay
commented abit then built the game
2024-07-05 23:30:15 +08:00

139 lines
3 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else if (instance != null && instance != this)
{
Destroy(gameObject);
}
}
void Start()
{
setmaster();
setMusic();
setSFX();
}
public int playerHealth = 100;
public bool petrolCollected;
public bool gotGenerator;
public bool paused = false;
public AudioClip bang;
public AudioClip reload1;
public AudioClip reload2;
public AudioClip handling;
public Slider masterSlider;
public Slider musicSlider;
public Slider sfxSlider;
public AudioMixer mixer;
public GameObject optionsScreeen;
bool Options;
public GameObject start;
public GameObject pauseMenu;
public GameObject endScreen;
public void Pause()
{
if (!paused)
{
pauseMenu.SetActive(true);
Time.timeScale = 0f;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Confined;
GameObject.Find("hand position").GetComponentInChildren<Gun>().readyToShot = false;
paused = true;
}
else if (paused)
{
pauseMenu.SetActive(false);
Time.timeScale = 1f;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
GameObject.Find("hand position").GetComponentInChildren<Gun>().readyToShot = true;
paused = false;
}
}
public void Exit()
{
Application.Quit();
}
public void endGame()
{
endScreen.SetActive(true);
}
public void Play()
{
Time.timeScale = 1f;
pauseMenu.SetActive(false);
start.SetActive(false);
}
public void options()
{
if (Options)
{
optionsScreeen.SetActive(false);
Options = false;
}
else if (!Options)
{
optionsScreeen.SetActive(true);
Options = true;
}
}
public void damagePlayer(int damage)
{
playerHealth -= damage;
}
public void setmaster()
{
float volume = masterSlider.value;
mixer.SetFloat("master", Mathf.Log10(volume) * 20);
}
public void setMusic()
{
float volume = musicSlider.value;
mixer.SetFloat("music", Mathf.Log10(volume) * 20);
}
public void setSFX()
{
float volume = sfxSlider.value;
mixer.SetFloat("sfx", Mathf.Log10(volume) * 20);
}
void Update()
{
if(playerHealth<=0)
{
die();
}
}
void die()
{
endGame();
endScreen.GetComponentInChildren<TextMeshProUGUI>().text="you died while trying to escape the planet try again next time";
}
}