- Home /
Question by
mrnee · Nov 22, 2012 at 09:49 PM ·
javascriptguilabel
GUILabel doesn't show up
function OnGUI (){
if (showGameButtons){
// Player ends turn by banking points earned in this turn
if (GUI.Button (Rect(10,40,100,30),"Bank")){
if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score==0){
if (PreScore.guiScore>=1000){
GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
endTurn();
}else{
print("shikaka");
GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleast 1000 points to open the game!",alertStyle);
}
}
if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score>0){
if (PreScore.guiScore>=350){
GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
endTurn();
}else{
GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleats 350 point to bank!",alertStyle);
}
}
}
if (GUI.Button (Rect(130,40,100,30), "Keep")) {
// to press this button preScore must be bigger than 0;
if (PreScore.preScore>0){
PreScore.turnScore += PreScore.preScore;
PreScore.preScore = 0;
gameObject.GetComponent("PreScore").reset = true;
gameObject.GetComponent("Roll").enabled = true;
print(PreScore.preScore);
KillDice();
}else{
// pazinojums, ka jaatzime vismaz viens kaulins
}
}
}
if (!showGameButtons){
GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You can't score anything with these dice!",alertStyle);
if (GUI.Button (Rect(((Screen.width - 120) / 2)+10, Screen.height/2+25,100,30),"End Turn")){
endTurn();
}
}
}
The problem is that it won't show alert label "You need atleast 1000 points to open the game!". Any ideas why? it prints "shikaka" to console :S
Comment
Best Answer
Answer by whydoidoit · Nov 22, 2012 at 09:57 PM
It would only show it while the button was held down. You should initialize some time when that message is triggered and then show it while the time is less than that target:
var message1Time : float;
var message2Time : float;
function OnGUI (){
if (showGameButtons){
// Player ends turn by banking points earned in this turn
if (GUI.Button (Rect(10,40,100,30),"Bank")){
if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score==0){
if (PreScore.guiScore>=1000){
GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
endTurn();
}else{
print("shikaka");
message1Time = Time.time + 4;
}
}
if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score>0){
if (PreScore.guiScore>=350){
GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
endTurn();
}else{
message2Time = Time.time + 4;
}
}
}
if(message1Time > Time.time)
{
GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleast 1000 points to open the game!",alertStyle);
}
if(message2Time > Time.time)
{
GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleats 350 point to bank!",alertStyle);
}
if (GUI.Button (Rect(130,40,100,30), "Keep")) {
// to press this button preScore must be bigger than 0;
if (PreScore.preScore>0){
PreScore.turnScore += PreScore.preScore;
PreScore.preScore = 0;
gameObject.GetComponent("PreScore").reset = true;
gameObject.GetComponent("Roll").enabled = true;
print(PreScore.preScore);
KillDice();
}else{
// pazinojums, ka jaatzime vismaz viens kaulins
}
}
}
if (!showGameButtons){
GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You can't score anything with these dice!",alertStyle);
if (GUI.Button (Rect(((Screen.width - 120) / 2)+10, Screen.height/2+25,100,30),"End Turn")){
endTurn();
}
}
}
Your answer
Follow this Question
Related Questions
Timer Between Labels 2 Answers
[Solved]Label is not a member of GUI anymore. 1 Answer
Setting Scroll View Width GUILayout 1 Answer
How Would I Make A GUI Label Fade After A Certain Amount Of Time? 1 Answer
For Loop GUILayout.Label Problems 1 Answer