I know this might be super simple. Here is my code so far:
#pragma strict
static var currentScore : int = 0;
var offsetX : float = 22.43;
var offsetY : float = 376.6;
var sizeX : float = 148.86;
var sizeY : float = 25.2;
function OnGUI () {
GUI.Box (new Rect (offsetX, offsetY, sizeX, sizeY), "Pages Collected: 4/" + currentScore);
}
I need it so when “currentScore” equals 4 it replaces the “Pages Collected: 4/” To another text. Would this be possible if so can someone help me?
~~Lost Syndicate
I would like it to say “BEAST MODE ACTIVATED”
Hey there. Should be something like:
#pragma strict
static var currentScore : int = 0;
var offsetX : float = 22.43;
var offsetY : float = 376.6;
var sizeX : float = 148.86;
var sizeY : float = 25.2;
//New
var firstLineOfText : string = "Pages Collected: 4/";
var secondLineOfText : string = "BEAST MODE ACTIVATED";
var itemText : string = "";
function OnGUI () {
GUI.Box (new Rect (offsetX, offsetY, sizeX, sizeY), itemText + currentScore);
}
//then somewhere in the code just set itemText = firstLineOfText or secondLineOfText
Hope that helps you!
Simple enough:
function OnGUI () {
var text;
if (currentScore != 4) { text = "Pages Collected: 4/" + currentScore; }
else { text = "Something else; " + currentScore; } // this becomes activate when currentScore == 4
GUI.Box (new rect (offsetX, offsetY, sizeX, sizeY), text);
}
Note: this is based on C# code, because I don’t know UnityScript, but it should be very similar in UnityScript as well. Also, possibly you meant "when currentScore is greater than 4. In that case just change != to <.
Finally, I would avoid using the old UI system, it is slow, very limited in its capabilities, and difficult to make it nice. If you decide so, look up Unity UI.