- Home /
Connecting 2 strings in a GUI text area - C#
So In my game I want it so it outputs "Your current time is: Insert time here". However when I actually put this into practice It either just outputs "Your current time is: Your current time is" or it just outputs the number without any text.
Code: void OnGUI() { CurrentTime = GUI.TextArea(new Rect(PosX,PosY,SizeX,SizeY), "Current time: " + CurrentTime); CurrentHighScore = GUI.TextArea(new Rect(0,20,SizeX,SizeY), "Current highscore: " + CurrentHighScore);
}
void Convert(){
CurrentTime = System.Convert.ToString(timer);
CurrentHighScore = System.Convert.ToString(highscore);
}
}
Answer by Riderfan · Apr 10, 2016 at 02:20 PM
First of all, you don't need to use System.Convert.ToString(). Just use;
timer.ToString();
highscore.ToString();
The other thing that is going on is that, it looks like, you're setting a variable value in the same line of code that you're using it. This works, but it's not the best codeing practice in the world.
Perhaps try something like;
public string DisplayTime()
{
return "Your Current Time Is:" + timer.toString();
}
void OnGUI()
{
GUI.TextArea(new Rect(PosX,PosY,SizeX,SizeY), DisplayTime());
}