- Home /
Question by
pinticoder · May 23, 2021 at 12:03 PM ·
scripting problemguitext
I have a problem with Unity UI Text
hello guys i have a problem. I'm new to Unity so I'd appreciate it if you could help. The problem is that I used Text in the UI in the condition that is PlayerOne in the condition structure I wrote at the bottom and the text I want comes after the condition is met, but when I press the restart button, the text does not disappear from the screen. In PlayerTwo, I used the GUI Label and the game's restart button works when I press it, but the problem with it is that I can't rotate the text, unfortunately it just stays on the same plane.
Note: I have defined the Restart button to reset the game, so the scores are zero again.
public static int PlayerScore1 = 0;
public static int PlayerScore2 = 0;
GameObject theBall;
public Text overGame;
public bool PlayerOne = false;
public bool PlayerTwo = false;
void Start()
{
theBall = GameObject.FindGameObjectWithTag("Ball");
}
public static void Score(string wallID)
{
if(wallID == "TopWall")
{
PlayerScore1++;
}
if(wallID == "DownWall")
{
PlayerScore2++;
}
}
public void RestartButton()
{
PlayerScore1 = 0;
PlayerScore2 = 0;
theBall.SendMessage("RestartGame", 0.5f, SendMessageOptions.RequireReceiver);
}
// Update is called once per frame
void OnGUI()
{
PlayerOne = false;
PlayerTwo = false;
***if (PlayerOne == false)
{
if (PlayerScore1 == 2)
{
overGame.text = "Player One Win !!";
theBall.SendMessage("ResetBall", null, SendMessageOptions.RequireReceiver);
PlayerOne = true;
}
}
if (PlayerTwo == false) {
if (PlayerScore2 == 2)
{
GUI.Label(new Rect(Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER TWO WINS");
theBall.SendMessage("ResetBall", null, SendMessageOptions.RequireReceiver);
PlayerTwo = true;
}
}***
}
Comment
Why are you using OnGUI and SendMessage? Just create a method to check the winner after some change in their scores.