Help with text to appear only once and not every time the scene is loaded
Hello, i need help with text that disappears. So i have a script like this:
using UnityEngine; using System.Collections; using UnityEngine.UI; public class Nice : MonoBehaviour { public Text test; void Start()
{
test.text = "";
}
void Update()
{
if (Score.ScoreValue == 5)
{
test.text = "Nice!";
Destroy(test, 1);
}
}
}
It works well when the score is 5 but i have another script that resets the scene:
if(player.holdingBall == false) { resetTimer -= Time.deltaTime; if(resetTimer<=0) { SceneManager.LoadScene("Game"); } }
So if i miss and don't score then the score is still 5 and the text "Nice" appears once again.
How to make to appear only once when the score is 5 and not every time the scene resets if i miss the ball.
Thanks in advance.
Is the Score script beeing destroyed when you reload the scene? Do you want the score go back to 0 when it is reloaded?
No, the reason why the scene is resetting so when i throw the ball ins$$anonymous$$d of picking up i restart the scene to have the ball once again and the score is not resetting.
Answer by Obsessi0n · Feb 02, 2018 at 03:02 PM
private bool firstTime = True;
void Update()
{
if (Score.ScoreValue == 5 && firstTime)
{
test.text = "Nice!";
Destroy(test, 1);
firstTime = false;
}
}
if the Nice script is beeing destroyed when scene is loaded use ins$$anonymous$$d this.
//Add this on the Score script
public bool firstTime = True;
void Update()
{
if (Score.ScoreValue == 5 && Score.firstTime)
{
test.text = "Nice!";
Destroy(test, 1);
firstTime = false;
}
}
Your answer
Follow this Question
Related Questions
How To Load TTF Font From External File 0 Answers
How to link up instantiated text in list to allow buttons to adjust number shown, c# 1 Answer
Removing an item from Inventory and updating item count on HUD 0 Answers
UI Text got messed after building the game 0 Answers
Gui Text won't turn off 0 Answers