- Home /
2D Game: main menu button dont work
Hello, this is my first question.
I have 3 scenes: - main - level_selection - level_001
In the scene "main" I have one texture (arcade) with a box collider. When I click on it, the scene "level_selection" appear.
In the scene "level_selection" I have another texture (level image) with a box collider, and when I click on it, the scene "level_001" appear.
Now, in the scene "level_001", I have two textures with one box collider on each. One is the texture for a "exit" button and the other is the texture for a "main menu" button.
When I click on the "exit" button, it close the app, and when I click on the "main menu" button, the scene "main" appear.
I use this codes:
GoMainMenu.js
function OnMouseDown () { Application.LoadLevel("level_001"); }
GoLevel1.js
function OnMouseDown () { Application.LoadLevel("main"); }
GoLevelSelection.js
function OnMouseDown () { Application.LoadLevel("level_selection"); }
This is the problem, I do this steps:
In "main" I click on Arcade (go to level_selection).
In "level_selection" I click on the level image (go to level_001).
In "level_001" I click on the main menu button (go to main).
In "main" I click on Arcade (go to level_selection).
In "level_selection" I click on the level image (go to level_001).
In "level_001" I click on the main menu button and the button dont work, nothing happen.
I dont know why. Anybody can help me? Im starting using unity about 2 days and i dont know a lot of things.
Sorry if my english is not good, I speak spanish.
Thank you.
You're english is good enough :) Could you please post your code? That way, we might be able to see what you're doing wrong.
Thank you for answer. Id post the code of the js im using on the buttons. You think is something wrong on the scripts id use in "level_001" scene?
I have 3 scripts with an instatiate creating objects in random positions.
Creator1.js
var egg : GameObject;
InvokeRepeating("Drop", 2, 6);
function Drop() {
var position : Vector3 = Vector3( -5, Random.Range(1.2, 2.3), 0);
Instantiate(egg, position, Quaternion.identity);
}
And I use other script to destroy the objects when them collide with another called "nest" and "terrain".
Destroy.js
function OnCollisionEnter2D(coll: Collision2D) {
if (coll.gameObject.tag == "nest")
Destroy(gameObject);
if (coll.gameObject.tag == "terrain")
Destroy(gameObject);
}
And i use other script to move my character
PlayerControl.js
var moveLeft : $$anonymous$$eyCode; var moveRight : $$anonymous$$eyCode; var moveUp : $$anonymous$$eyCode; var speed : float = 10; var jump : float = 0; var jumpSpeed : float = 5; var jumpTimer : float = 0;
function Update () { if (jump == 1){ jumpTimer = jumpTimer +1 ; if (jumpTimer >= 50){ jumpTimer = 0; jump = 0;}} if (Input.Get$$anonymous$$ey(moveLeft)){ rigidbody2D.velocity.x = speed -1; } else if (Input.Get$$anonymous$$ey(moveRight)){ rigidbody2D.velocity.x = speed; } else { rigidbody2D.velocity.x = speed 0; } if (Input.Get$$anonymous$$eyDown (moveUp)){ if (jump == 0){ rigidbody2D.velocity.y = jumpSpeed; jump = 1;}} }
Do you see something wrong impacting on the main button?
I have other button on my "level_001" scene to close the app:
Exit.js
function On$$anonymous$$ouseDown () { Application.Quit(); }
this button doesnt work neither when the main button dont work.
Thank you for your help.
You should edit your original question to provide this new information ins$$anonymous$$d of posting an answer. Answers are for solutions only.
Do also remember to format your code using the 101010 button above the text box.
Your answer
Follow this Question
Related Questions
gui text button dont work 1 Answer
how to make a button work on main menu? 0 Answers
Sliding sub-menu from behind an icon 0 Answers
How to Change Menu Button Rollover States with GameObjects 1 Answer
Close GUI help. 1 Answer