OK, I know I’m doing something wrong here. I’m trying to make a GUI.Button in a new scene I’m writing with this code:
void Start () {
// Define temporary variables
float startButtonTop;
float startButtonLeft;
// Determine where the start button will be
startButtonTop = transform.position.y - titleHeight - 50f;
startButtonLeft = transform.position.x + (titleWidth / 4f);
startButtonWindow = new Rect(startButtonLeft, startButtonTop, (titleWidth / 2f), 50f);
}
void OnGUI () {
if(GUI.Button(startButtonWindow, "START"))
{
Debug.Log("Button pressed");
}
}
The script is attached to a SpriteRenderer. The titleHeight and titleWidth variables are floats, and the Debug.Log is a placeholder. What’s happening is nothing; the GUI.Button won’t show up. This is extremely confusing for me, as similar code attached to a SpriteRenderer in a different scene works fine. Does anyone know what I’m doing wrong?