flappy_bird/Assets/Scripts/LogicScript.cs
2025-03-09 11:40:35 +05:30

58 lines
1.4 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LogicScript : MonoBehaviour
{
public int playerScore;
public Text ScoreText;
public Text HighScoreText;
public Text CurrentSCoreText;
public GameObject gameOverScreen;
void Start ()
{
UpdateHighScore();
}
void UpdateHighScore()
{
int HighScore = 0;
if(PlayerPrefs.HasKey("HighScore"))
{
HighScore = PlayerPrefs.GetInt("HighScore");
}
if(playerScore > HighScore)
{
PlayerPrefs.SetInt("HighScore",playerScore);
PlayerPrefs.Save();
}
HighScoreText.text = HighScore.ToString();
}
[ContextMenu("Increase Score")]
public void addScore(int ScoreToAdd)
{
playerScore = playerScore + ScoreToAdd;
ScoreText.text = playerScore.ToString();
CurrentSCoreText.text = playerScore.ToString();
UpdateHighScore();
}
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