- Home /
How to create a pop-up window on mouse click?
I'm relatively new to scripting so I apologise if this is a silly question. I've got a scene set up with multiple cubes that are interactive. They change colours when my crosshair hovers over them and when you click the left mouse button, it loads up a new scene.
My question is, how would I change this setup to have a pop up window appear on mouse click instead of a new level loading (and possibly disappear on a 2nd mouse click)? I've been messing around with the script but I'm not sure which script I should be editing to enable this pop up window.
My raycast script is as follows:
public class selectObject : MonoBehaviour {
public RaycastHit hit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void LateUpdate () {
Ray ray = Camera.main.ScreenPointToRay (new Vector3 (Screen.width / 2, Screen.height / 2, 0));
if(Physics.Raycast (ray, out hit, 5)) {
if(hit.collider.gameObject.GetComponent<interactHighlight>()!= null){
hit.collider.gameObject.GetComponent<interactHighlight>().OnLookEnter ();
}
if(hit.collider.gameObject.GetComponent<mehScript>()!= null) {
hit.collider.gameObject.GetComponent<mehScript>().OnLookEnter ();
}
if(hit.collider.gameObject.GetComponent<mehScript2>()!= null) {
hit.collider.gameObject.GetComponent<mehScript2>().OnLookEnter ();
}
}
}
}
And the interactHighlight scripts all follow this structure:
public class interactHighlight : MonoBehaviour {
public GUIText target;
private bool selected = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
selected = false;
}
public void OnLookEnter () {
renderer.material.color = Color.red;
target.text = "Left Click to See More Information";
selected = true;
}
void OnGUI () {
Event e = Event.current;
if(Input.GetMouseButtonDown(0) && selected) {
Application.LoadLevel ("2_levelTest");
}
}
}
What would I have to change to enable a pop up window? Thanks in advance
Answer by KRanges · Apr 22, 2014 at 04:25 AM
Are you looking for our own custom window within the game? or are you looking for a message box with ok | cancel buttons? If your looking for the first one which i assume you are, see this
Thanks, I had a look at the link and I managed to get a GUI window to pop-up :)
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Saving final score and displaying on main menu 1 Answer
null texture passed to GUI.DrawTexture 0 Answers