0% found this document useful (0 votes)
24 views

LevelManager Cs

Uploaded by

hkhandelwal2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

LevelManager Cs

Uploaded by

hkhandelwal2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using UnityEngine;

using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour


{

public static LevelManager levelManager;

private int currentPoints = 0;


private int highscore;
public GameObject bronze;
public GameObject silver;
public GameObject gold;

public Text pointsText;

public AudioSource pointAudio;


public AudioSource specialAudio;
public GameObject endMenu;

void Start()
{
bronze.SetActive(false);
silver.SetActive(false);
gold.SetActive(false);
}

void Awake()
{
if (levelManager == null)
{
levelManager = this;
highscore = PlayerPrefs.GetInt("Highscore");

GetAudioPreferences();
}
else if (levelManager != this)
{
Destroy(gameObject);
}
}

private void GetAudioPreferences()


{
float appVolume = PlayerPrefs.GetFloat("Volume");
appVolume = appVolume == 0f ? 0.5f : appVolume;

specialAudio.volume = appVolume;
pointAudio.volume = appVolume;
}

public void UpdatePoints()


{
currentPoints++;
pointsText.text = currentPoints.ToString();
if(currentPoints <= 5)
{
bronze.SetActive(true);
}
else if(currentPoints > 5 && currentPoints <= 10)
{
bronze.SetActive(false);
silver.SetActive(true);
}
else if(currentPoints > 10)
{
silver.SetActive(false);
gold.SetActive(true);
}
if ((currentPoints % 10 == 0 && currentPoints != 10)|| currentPoints == 6
|| currentPoints == 11)
{
specialAudio.Play();
}
else
{
pointAudio.Play();
}
}

public void UpdateHighscore()


{
if (currentPoints > highscore)
{
highscore = currentPoints;
PlayerPrefs.SetInt("Highscore", highscore);
}
}

public void OpenEndMenu()


{
Time.timeScale = 0;
UpdateHighscore();
endMenu.SetActive(true);
}

public void RestartGame()


{
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

public void GoMainMenu()


{
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}

You might also like