I am creating a GUI menu but i’m getting some problems.
heres my script
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour {
private Rect windowRect;
public float boxW;
public float boxH;
public float boxX;
public float boxY;
public float bottonW;
public float bottonH;
public float bottonX;
public float bottonY;
public float offset;
public GUISkin mySkin;
public Texture map;
public float textureY;
public float textureX;
public float textureWidth;
public float textureHeight;
public bool on;
public bool onMap;
// Use this for initialization
void Start () {
boxW =Screen.width - 200f;
boxH = Screen.height - 250f;
boxX = (Screen.width / 2) - (boxW / 2);
boxY = (Screen.height / 2) - (boxH / 2);
bottonW = 196 ;
bottonH = 33.7f;
bottonX = boxX / 3 ;
bottonY = 100;
offset = 83;
textureX = 239;
textureY = 86;
textureHeight = 141;
textureWidth = 92;
}
void OnGUI() {
GUI.skin = mySkin;
if(on == true){
windowRect = GUI.Window( 0, windowRect, MyWindow, "Menu");
}
}
// Update is called once per frame
public void Update() {
windowRect = new Rect(boxX, boxY, boxW, boxH );
}
private void MyWindow( int id ) {
Map();
if(onMap == true){
mapTexture();
}
Character();
Sound();
Graphic();
Save();
Exit();
}
private void Map() {
if (GUI.Button(new Rect(bottonX, bottonY + (offset * 0), bottonW, bottonH), "Map"));
Debug.Log("Clicked the button with text");
//else
//onMap = false;
}
private void Character() {
if (GUI.Button(new Rect(bottonX, bottonY + offset * 1, bottonW, bottonH), "Character"));
}
private void Sound() {
if (GUI.Button(new Rect(bottonX, bottonY + offset * 2, bottonW, bottonH), "Sound"));
}
private void Graphic() {
if (GUI.Button(new Rect(bottonX, bottonY + offset * 3, bottonW, bottonH), "Graphics"));
}
private void Save() {
if (GUI.Button(new Rect(bottonX, bottonY + offset * 4, bottonW, bottonH), "Save"));
}
private void Exit() {
if (GUI.Button(new Rect(bottonX, bottonY + offset * 5, bottonW, bottonH), "Exit"));
}
private void mapTexture(){
GUI.DrawTexture(new Rect(textureX, textureY, boxW - bottonW - textureWidth, boxH - textureHeight), map, ScaleMode.StretchToFill, true, 10.0F);
}
}
The problem that I am having is that when I turn on my menu and its bool is set to true ; my botton also gets pressed.