Simple Menu Script

Hello!
I want to make a simple menu script,i watched/read some tutorials, but i don’t understand what is the problem. Here is the code:

 using UnityEngine;
        using System.Collections;
        
        public class Menu_Exit : MonoBehaviour {
        	
        	public bool isMenu_Exit = false;
        	
        	void OnMouseEnter()
        	{
        		renderer.material.color = Color.green;
        	}
        	
        	void OnMouseExit()
        	{
        		renderer.material.color = Color.black;
        	}
        	
        	void OnMouseDown()
        	{
        			Application.Quit();
        	}
        }

I have a mesh and this. When i start the application, nothing works. No color change, the application doesn’t closes.

I probed to write ‘‘if’’ after the void OnMouseDown(), not works.

Thank you!

Do you have a collider on the gameobject?

–

Yes, i added a box collider. But why i need collider? My mouse only has 2 axes, not 3 ( because this is a 3D menu ) This is problem?

–

I know a way to do a menu with 3d text in Unity. Do you want the script?

–

It would be great!

–

Are you running this in the inspector? I think Application.Quit() doesn't work when running in the inspector. The onMouse functions don't work on IOS if that's what you are trying. Other then that, it should work.

–

1 Answer

1

@Hydraxia the reason that nothings works is that you have no connection between any UI element (Text, Buttons etc.) and one of your functions.
If you want to do this you have to create some UIElements and connect it with your script.

You can do this when you first initialize your Element

  1. First write at the top :
    using UnityEngine.UI;
  2. then for example
    public Text (type of the UI) text (name of your UI)
  3. :
    if (Input.GetKeyDown(Keycode.Space) {
    Application.Quit();
    }

Please don't bump up post from 4 years ago.

–