Hello,
Ich have create a 3D-Menü, but I don’t understand how to click on the “3D-Text”.
Each text has an Box-Collider.
Here is a screenshot of my Menü:
http://www.abload.de/img/unbenanntutf12.png
Use the OnMouseDown function
OKay, but one Question, when I have Start and OnMouseDown, than Starts a new Level when I Press “Start” or “Multiplayer” or?
Can you make me a simple Code to understand where to usw more than one Button/3D-Text ?
var isStartButton : boolean;
var isExitButton : boolean;
function OnMouseDown() {
if(isStartButton == true){
Application.LoadLevel("LevelName");
}
if(isExitButton == true){
Application.Quit();
}
}
For each button, tick the box in the inspector which applys to the menu item.
If your going to have several buttons, it’ll be cleaner to use an array. Both will behave the same.
var menuItems : boolean[];
function OnMouseDown() {
if(menuItems[0]){
Application.LoadLevel("LevelName");
}
if(menuItems[1]){
Application.Quit();
}
}
Thanks, but I have a Problem:
When I press Start the Level Loads, that is so okay, but when I press Multiplayer, Einstellungne and Beenden, the Level starts also…
My/Your Code:
var menuItems : boolean[];
function OnMouseDown() {
if(menuItems[0]){
Application.LoadLevel(1);
}
if(menuItems[1]){
print("Multiplayer");
}
if(menuItems[2]){
Application.Quit();
}
if(menuItems[3]){
Application.Quit();
}
if(menuItems[4]){
Application.Quit();
}
}
function OnMouseEnter () {
renderer.material.color = Color.red;
}
function OnMouseExit () {
renderer.material.color = Color.white;
}
And a Screenshot what I have ticked in the Insepctor:
Start 3D-Text: http://www.abload.de/img/start-3d-textgod9k.png
Multiplayer 3D-Text: http://www.abload.de/img/multiplayerusdmm.png
You only need to tick the box which is relevant to the object the script is on, so for example, on your play button, only tick element0, on your multiplayer button, only tick element1 and so on.
I get this error:
IndexOutOfRangeException: Array index is out of range.
Button.OnMouseDown () (at Assets/Scripts/Button.js:20)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents()
You don’t have five elements in the menuItem array.
thanks, it works