I have created a button with photoshop and i am trying to use it instead of my buttons I created.
Till now I have a script with C# that is attached to the main camera. The script basically makes the main menu for me but i would like to change the buttons generated with an image I designed.
This is what I have till now:
using UnityEngine;
using System.Collections;
public class myMenu : MonoBehaviour {
private delegate void MenuDelegate();
private MenuDelegate menuFunction;
private float screenHeight;
private float screenWidth;
private float buttonHeight;
private float buttonWidth;
// Use this for initialization
void Start () {
screenHeight = Screen.height;
screenWidth = Screen.width;
buttonHeight = screenHeight * 0.3f;
buttonWidth = screenWidth * 0.4f;
menuFunction = anyKey;
}
void OnGUI()
{
menuFunction();
}
void anyKey()
{
if(Input.anyKey)
{
menuFunction = mainMenu;
}
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.Label(new Rect(screenWidth * 0.45f, screenHeight * 0.45f, screenWidth * 0.1f, screenHeight * 0.1f), "Press any key to continue");
}
void mainMenu()
{
// Main Menu
// Start Game
// How to Play
// Settings
// Quit
GUI.Box(new Rect((screenWidth - buttonWidth) * 0.6f, screenHeight * 0.05f, buttonWidth * 0.7f, buttonHeight * 2.5f), "Main Menu");
if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.15f, buttonWidth * 0.4f, buttonHeight * 0.4f), "Start Game"))
{
Application.LoadLevel ("Level1");
}
if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.3f, buttonWidth * 0.4f, buttonHeight * 0.4f), "How to Play"))
{
}
if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.45f, buttonWidth * 0.4f, buttonHeight * 0.4f), "Settings"))
{
}
if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.6f, buttonWidth * 0.4f, buttonHeight * 0.4f), "Quit Game"))
{
Application.Quit();
}
}
}
My goal at the moment is to find a way how to make the script load the image and once clicked it does something like application.quit.
i have never coded in C# before, just Java and .Net, but i can understand C# since they are similar.
and what if i just simply drag and drop it in front of the main camera, making the camera facing 1 position during the main menu. Will i achieve the same results? what happens if the game gets maximized? will the GUI scatter? Sorry but i am still new to unity