- Home /
Question by
MelodiousNocturne · Aug 05, 2014 at 10:38 AM ·
onguibutton trigger events
OnGui (c#) Question, want to make a button that opens a box
Trying to make a button in OnGui (c#) and I want the button to open a new rect(angle) and I have no idea how. I literally started learning last night so it's probably something really simple I'm missing.
This is the code I have so far:
using UnityEngine; using System.Collections;
public class Menu : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUI.Box (new Rect (640, 360, 640, 360), "Menu");
if (GUI.Button (new Rect (920, 390, 80, 20), "Inventory")) {
//Debug.Log("Does nothing yet");
GUI.Box (new Rect(10, 10, 200, 200), "inventory");
}
}
}
Thank you for your help :)
Comment
Answer by Mehul-Rughani · Aug 05, 2014 at 11:16 AM
Hope You Are Looking For This....
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public bool flag;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
if(!flag)
{
GUI.Box (new Rect (Screen.width/2-100, Screen.height/2-100, 150, 150), "Menu");
if (GUI.Button (new Rect (Screen.width/2-60, Screen.height/2-50, 80, 20), "Inventory"))
flag=true;
}
if(flag)
GUI.Box (new Rect (Screen.width/2-100, Screen.height/2-100, 200, 200), "Inventory");
}
}
Your answer
Follow this Question
Related Questions
Simple Program counts OnGUI() If(Button)else(Anywhere but button) Score twice 1 Answer
Drawing a GUI box by specifying the two corners 1 Answer
Placing a chat bubble above a character's head in a 3d environment 2 Answers
Saving a button in PlayerPrefs 2 Answers
Editor GUI Drag Selection Box 1 Answer