- Home /
Question about GUILayout not appearing
Hi guys, i have a problem. My code compiles, the debug.log shows but the GUILayout doesnt appear....it only appears if i put it over the IFs, see the comments. Here's my code, thanks again for your help !
using UnityEngine;
using System.Collections; using UnityEditor;
public class TowerMenuPopUp : MonoBehaviour {
Ray ray;
RaycastHit hit;
GameObject guardian;
int guardianX;
int guardianY;
int guardianZ;
void Start ()
{
guardian = GameObject.FindGameObjectWithTag("GuardianPos");
guardianX = (int) guardian.transform.position.x;
guardianY = (int) guardian.transform.position.y;
guardianZ = (int) guardian.transform.position.z;
}
void Update ()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
}
void OnGUI()
{
/*GUILayout.BeginArea(new Rect(10,10,100,100));
GUILayout.Button("Click me");
GUILayout.Button("Or me");
GUILayout.EndArea();*/
if(Physics.Raycast(ray,out hit, Mathf.Infinity))
{
if (hit.transform.tag == "Guardian")
{
if(Input.GetMouseButtonDown(0))
{
Handles.color = Color.green;
Handles.DrawWireDisc(guardian.transform.position,Camera.main.transform.position, 50.0f);
GUILayout.BeginArea(new Rect(10,10,100,100));
GUILayout.Button("Click me");
GUILayout.Button("Or me");
GUILayout.EndArea();
Debug.Log("WTF");
}
}
}
}
}
Answer by DaveA · Mar 23, 2012 at 08:26 PM
You should not be doing Raycast or GetMouseButtonDown in OnGUI. Do that in Update, and set a variable with the state you want to use in OnGUI to display the gui.
Answer by Stonemove420 · Mar 23, 2012 at 09:12 PM
ok so my condition is the problem, if i use a variable in the update, A.k.a boolean, will it work ? When the boolean is set to true with the GetMouseButtonDown, {pops up menu} and i can use the same boolean to close the menu ?
Your answer
Follow this Question
Related Questions
Touchscreen for unity 2 Answers
How to output a file to a single string? 1 Answer
GUI custom textfield cursor rendering 2 Answers
Detecting if mouse position is inside rect 2 Answers
iTween & gesture 0 Answers