- Home /
The question is answered, right answer was accepted
Why doesn`t my GUI Button show up?
I have a C# Script (for a 2D platformer) which for the most part works but the only thing that doesn`t work on it is the GUI button and I don`t know why(it is the on with the if before it). All of the other Labels work other than the Retry Button.
Here is the Script:
using UnityEngine;
using System.Collections;
public class GameOverScript : MonoBehaviour {
int score = 0;
void Start () {
score = PlayerPrefs.GetInt ("Score");
}
void OnGUI()
{
GUI.Label(new Rect(Screen.width / 2 - 40, 50, 80, 30), "GAME OVER");
GUI.Label (new Rect(Screen.width / 2 - 40, 300, 80, 30), "Score: " + score);
if(GUI.Button(new Rect(Screen.width / 2 - 30, 350, 60, 30), "Retry?"))
{
Application.LoadLevel(0);
}
}
}
Not sure if this is your problem, but your last label appears to partly overlap the rectangle you use for your Button. You should be seeing a piece of the button though.
I dont really know, where is your problem but the statement if (GUI.Button....) mean that if you click on that button, that something will happend.
Can you be a little more specific, does your button not appear, or does clicking on it do nothing?
No, the button and the "Retry?" text doesn`t appear at all. The players score and the "GA$$anonymous$$E OVER" text appears, its just that the button and its text "Retry?" is not showing at all.
What I have done is created a new scene with this script and attached it to a camera. I then added this scene in build so that it has a 1 next to it. When I lose in the game, Scene one should appear with the texts and button, but the button (along with the Retry text) is not visible anywhere.
Check your Y-Value (its to high put logic for that) may be you will get what you are looking
Answer by Chadley · Aug 01, 2014 at 02:19 PM
"Check your Y-Value (its to high put logic for that) may be you will get what you are looking" - VIPINSIRWANI
Thank you so much VIPINSIRWANI. I lowered my Y-Value down to 200 and now the button appears , thank you.
Follow this Question
Related Questions
Problem with Force on rigidbody, not always the same force 0 Answers
buttons not working in android. 1 Answer
2D Buttons 1 Answer
Mouse Click to keyCode 1 Answer
Getting a custom class to contain a certain script. 1 Answer