- Home /
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!
Yes, i added a box collider. But why i need collider? $$anonymous$$y 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?
Are you running this in the inspector? I think Application.Quit() doesn't work when running in the inspector.
The on$$anonymous$$ouse functions don't work on IOS if that's what you are trying.
Other then that, it should work.
Answer by PadExe · Aug 03, 2017 at 06:00 PM
@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(); }
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Problem with Pause and Pause Menu Script 1 Answer
[Newbie] Simple Menu script c# 1 Answer
When do we need to use Class? 1 Answer
how to create Magnetic repulsion ? 0 Answers