0% found this document useful (0 votes)
10 views2 pages

3

Uploaded by

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

3

Uploaded by

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

using System.

Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour


{

[Header("Score Elements")]
public int score;
public int highscore;
public Text scoreText;
public Text highscoreText;

[Header("GameOver")]
public GameObject gameOverPanel;
public Text gameOverPanelScoreText;
public Text gameOverPanelHighScoreText;

private void Awake()


{
gameOverPanel.SetActive(false);
GetHighscore();
}

private void GetHighscore()


{

highscore = PlayerPrefs.GetInt("Highscore");
highscoreText.text = "Best: " + highscore;
}

public void IncreaseScore(int points)


{
score += points;
scoreText.text = score.ToString();

if (score > highscore)


{
PlayerPrefs.SetInt("Highscore", score);
highscoreText.text = score.ToString();
}

}
public void OnBombHit()
{
Time.timeScale = 0;

gameOverPanelScoreText.text = "Score: " + score.ToString();


gameOverPanelHighScoreText.text = "Best: " + highscore.ToString();
gameOverPanel.SetActive(true);

Debug.Log("Bomb hit");
}

public void RestartGame()


{

score = 0;
scoreText.text = score.ToString();

gameOverPanel.SetActive(false);

foreach (GameObject g in GameObject.FindGameObjectsWithTag("Interactable"))


{
Destroy(g);
}

Time.timeScale = 1;
}

You might also like