Hi guys,
Im trying to show a groupbox message when I click in one button…
I have 2 classes… my “main” class.. e the other one named “alert”.
The problem is: if I put the dialog.showDialog("test"); on button event .. this doesnt work ![]()
But if I just put the dialog.ShowDialog(“test”); outside of Button click.. when my game starts I can see the box.
Why?
Main.cs
======================================================================================
using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {
public Alert dialog = new Alert();
public Texture bg;
public GUIStyle btLogin;
public GUIStyle fieldUsername;
public string username;
public string pass;
void Start() {
username = "test";
pass = "";
}
void Update() {
}
void OnGUI() {
// Background
GUI.DrawTexture(new Rect(0, 0, 965, 675), bg);
if (GUI.Button(new Rect(686, 563, 219, 69), "LOGIN") {
if (username == "") {
print("null");
} else {
dialog.showDialog("Loginnnn...");
}
}
username = GUI.TextField(new Rect(685, 445, 220, 30), username, 50, fieldUsername);
pass = GUI.PasswordField(new Rect(685, 492, 220, 30), pass, "*"[0], 50, fieldUsername);
}
}
=======================================================================================
Alert.cs
using UnityEngine;
using System.Collections;
public class Alert {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void showDialog(string msg) {
GUI.BeginGroup(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
GUI.Box(new Rect(0, 0, 150, 150), "");
GUI.Label(new Rect(10, 40, 80, 30), msg);
GUI.EndGroup ();
}
}