I’m new to unity and I’ve started making a main menu for my game but I’ve run into an issue. When I hit play and change the resolution the buttons don’t move, they just stay put even if it goes off screen. I was wondering what would I change in my code to make it not move off of the screen.
The Code: C#
using UnityEngine;
using System.Collections;
public class MainMenuHolder : MonoBehaviour
{
public Texture2D background , LOGO;
public GUISkin myskin;
public string messageToDisplayOnClick = “Press Esc to go back!”;
private string clicked = "";
private void OnGUI()
{
//background
if (background != null)
GUI.DrawTexture (new Rect(0,0,Screen.width , Screen.height),background);
if (clicked == "" || clicked == "Options")
{
//Logo
if (LOGO !=null)
GUI.DrawTexture (new Rect((Screen.width/2)-509,30,200,200), LOGO);
//original: GUI.DrawTexture (new Rect((Screen.width/2)-509,30,200,200), LOGO);
}
if (clicked == "")
{
GUI.skin = myskin;
//Buttons
// original is: if (GUI.Button (new Rect((Screen.width/2) - 100,Screen.height/2,200,30) , "Play Game"))
if (GUI.Button (new Rect((Screen.width/2) - 510,Screen.height/2,200,30) , "Play Game"))
{
//code on what to do after clicked play
}
if (GUI.Button (new Rect((Screen.width / 2) - 510,( Screen.height / 2 )+50, 200,30), "Options"))
{
//code on what to do when options are clicked
clicked = "Options";
}
if (GUI.Button (new Rect((Screen.width / 2) - 510, (Screen.height / 2) + 100,200,30), "Credits"))
{
//Code on what to do when Credits is clicked
clicked = "Credits";
}
if (GUI.Button (new Rect((Screen.width / 2) - 510, (Screen.height / 2) + 150, 200, 30), "Quit Game"))
{
Application.Quit();
}
}
else if (clicked == "Options")
{
GUI.Window (0, new Rect((Screen.width / 2) - 100, Screen.height / 2, 200, 50) , optionsFunc , "Options");
}
else
{
GUI.Box (new Rect (0,0,Screen.width,Screen.height) , messageToDisplayOnClick);
}
}
private void optionsFunc(int id)
{
GUILayout.Box ("Volume");
if (GUILayout.Button ("Back"))
{
clicked = "";
}
}
private void Update()
{
if (clicked == "Credits" && Input.GetKey (KeyCode.Escape))
{
clicked = "";
}
if (clicked == "Options" && Input.GetKey (KeyCode.Escape))
{
clicked = "";
}
if (clicked == "Play Game" && Input.GetKey (KeyCode.Escape))
{
clicked = "";
}
}
}