Convert to TextMeshPro for game player
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,9 @@
|
|||||||
using UnityEngine;
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
public class Game : MonoBehaviour
|
public class Game : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float spawnRate = 1f;
|
private float spawnRate = 1f;
|
||||||
private float nextSpawnTime = 0f;
|
private float nextSpawnTime = 0f;
|
||||||
private int score = 0;
|
private int score = 0;
|
||||||
private int highscore = 0;
|
private int highscore = 0;
|
||||||
@@ -15,6 +16,9 @@ public class Game : MonoBehaviour
|
|||||||
private Rigidbody2D rb;
|
private Rigidbody2D rb;
|
||||||
public GameObject pausePanel;
|
public GameObject pausePanel;
|
||||||
public AudioSource songLoop;
|
public AudioSource songLoop;
|
||||||
|
public TMP_Text scoreText;
|
||||||
|
public TMP_Text highScoreText;
|
||||||
|
public TMP_Text boostText;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -27,9 +31,7 @@ public class Game : MonoBehaviour
|
|||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
screenWidth = Camera.main.orthographicSize * 2 * Camera.main.aspect;
|
screenWidth = Camera.main.orthographicSize * 2 * Camera.main.aspect;
|
||||||
|
highScoreText.text = $"High Score: {highscore}";
|
||||||
GameObject highScoreText = GameObject.Find("HighScoreText");
|
|
||||||
highScoreText.GetComponent<TextMesh>().text = $"High Score: {highscore}";
|
|
||||||
|
|
||||||
if (PlayerPrefs.GetInt("Setting2", 0) == 1 || Application.isMobilePlatform)
|
if (PlayerPrefs.GetInt("Setting2", 0) == 1 || Application.isMobilePlatform)
|
||||||
{
|
{
|
||||||
@@ -245,21 +247,20 @@ public class Game : MonoBehaviour
|
|||||||
if (pausePanel.activeSelf) return;
|
if (pausePanel.activeSelf) return;
|
||||||
MoveBird();
|
MoveBird();
|
||||||
SpawnBerries();
|
SpawnBerries();
|
||||||
GameObject boostText = GameObject.Find("BoostText");
|
|
||||||
|
|
||||||
if (boostLeft > 0)
|
if (boostLeft > 0)
|
||||||
{
|
{
|
||||||
boostLeft -= Time.deltaTime;
|
boostLeft -= Time.deltaTime;
|
||||||
boostText.GetComponent<TextMesh>().text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
boostText.text = "Boost expires in " + string.Format("{0:0.0}", boostLeft) + "s";
|
||||||
}
|
}
|
||||||
else if (slownessLeft > 0)
|
else if (slownessLeft > 0)
|
||||||
{
|
{
|
||||||
slownessLeft -= Time.deltaTime;
|
slownessLeft -= Time.deltaTime;
|
||||||
boostText.GetComponent<TextMesh>().text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
boostText.text = "Slowness expires in " + string.Format("{0:0.0}", slownessLeft) + "s";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
boostText.GetComponent<TextMesh>().text = "";
|
boostText.text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.JoystickButton7) || Input.GetKey(KeyCode.Joystick2Button7))
|
if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.JoystickButton7) || Input.GetKey(KeyCode.Joystick2Button7))
|
||||||
@@ -470,16 +471,14 @@ public class Game : MonoBehaviour
|
|||||||
|
|
||||||
void UpdateScore(int score)
|
void UpdateScore(int score)
|
||||||
{
|
{
|
||||||
GameObject scoreText = GameObject.Find("ScoreText");
|
|
||||||
GameObject highScoreText = GameObject.Find("HighScoreText");
|
|
||||||
if (score > highscore)
|
if (score > highscore)
|
||||||
{
|
{
|
||||||
highscore = score;
|
highscore = score;
|
||||||
}
|
}
|
||||||
PlayerPrefs.SetInt("HighScore", highscore);
|
PlayerPrefs.SetInt("HighScore", highscore);
|
||||||
PlayerPrefs.Save();
|
PlayerPrefs.Save();
|
||||||
scoreText.GetComponent<TextMesh>().text = "Score: " + score;
|
scoreText.text = "Score: " + score;
|
||||||
highScoreText.GetComponent<TextMesh>().text = "High Score: " + highscore;
|
highScoreText.text = "High Score: " + highscore;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckIfGrounded()
|
private void CheckIfGrounded()
|
||||||
|
|||||||
Reference in New Issue
Block a user