46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
using Unity.VisualScripting;
|
|
public class LogicScript : MonoBehaviour
|
|
{
|
|
public int playerScore;
|
|
public Text ScoreText;
|
|
public Text HighScoreText;
|
|
public GameObject gameOverScreen;
|
|
|
|
[ContextMenu("Increase Score")]
|
|
public void addScore(int ScoreToAdd)
|
|
{
|
|
playerScore = playerScore + ScoreToAdd;
|
|
ScoreText.text = playerScore.ToString();
|
|
int HighScore = 0;
|
|
if(PlayerPrefs.HasKey("HighScore"))
|
|
{
|
|
HighScore = PlayerPrefs.GetInt("HighScore");
|
|
}
|
|
if(playerScore > HighScore)
|
|
{
|
|
PlayerPrefs.SetInt("HighScore",playerScore);
|
|
PlayerPrefs.Save();
|
|
}
|
|
HighScoreText.text = HighScore.ToString();
|
|
}
|
|
public void restartGame()
|
|
{
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
|
}
|
|
public void gameOver()
|
|
{
|
|
gameOverScreen.SetActive(true);
|
|
ScoreText.gameObject.SetActive(false);
|
|
}
|
|
public void exit()
|
|
{
|
|
SceneManager.LoadScene(0);
|
|
}
|
|
}
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
|
|