I don't know how to create a highscore gui text and display it at death screen
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class GameManagerScript : MonoBehaviour {
public int myScore;
public Text myScoreGUI;
public Transform bottomObstacle, topObstacle;
private AudioSource audioSource;
Text text;
// Use this for initialization
void Start()
{
text = GetComponent<Text>();
myScore = 0;
myScoreGUI = GameObject.Find("Text")
.GetComponent<Text>();
myScoreGUI.text = "Score: " + myScore.ToString();
InvokeRepeating("ObstacleSpawner", .5f, 1.5f);
audioSource = gameObject.GetComponent<AudioSource>();
}
void Update()
{
}
public void GmAddScore()
{
this.myScore++;
myScoreGUI.text = myScore.ToString();
audioSource.Play();
}
void ObstacleSpawner()
{
int rand = Random.Range(0, 2);
float topObstacleMinY = 2f,
topObstacleMaxY = 6f,
bottomObstacleMinY = -6f,
bottomObstacleMaxY = -2f;
switch (rand)
{
case 0:
Instantiate(
bottomObstacle,
new Vector2(
9f,
Random.Range(bottomObstacleMinY, bottomObstacleMaxY)
),
Quaternion.identity);
break;
case 1:
Instantiate(
topObstacle,
new Vector2(
9f,
Random.Range(topObstacleMinY, topObstacleMaxY)
),
Quaternion.identity);
break;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to add a Control Page to Pause Menu? 0 Answers
Location Does Not Change 1 Answer
Dragging rigidbody on ground 0 Answers
Why won't my random tile generator not working?? 0 Answers
[resolved] How do I deactivate a button once its height is < 40 in c# 0 Answers