- Home /
click gameobject, go to the next scene?
I'm coding this for an elevator and i want the button when clicked on the first floor to bring me to the second floor, there is is no worry about going back down, just up for the moment. Any help ASAP would be greatly appreciated! Thanks guys!
You can move your elevator in up direction to the second floor when the button is pressed
every floor is a different scene in unity, so that would be impossible unfortunately, there 6 floors, it was very choppy before i split the rooms in top different scenes.
Answer by CodeMasterMike · Jan 28, 2013 at 07:17 AM
If the button you press is a 3D object in the game, you could use something like this:
if(Input.GetMouseButtonDown(0) == true)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float rayLength = 500.0f;
RaycastHit hitInformation;
if(Physics.Raycast(ray, out hitInformation, rayLength) == true)
{
// Do some kind of check to make sure its the right button.
// It doesn't need to be the name, it can be anything really.
if(hitInformation.transform.name == yourButtonObjectName)
{
Application.LoadLevel(LevelIndex);
return;
}
}
}
If the user presses the left mouse button, a ray is created to see if the user is clicking on your specific 3d object button. And if there is a hit, then you load the scene you want.
If it is a 2D GUI button you have, then it's more easy.
if (GUI.Button(Rect(10,70,50,30),"2") == true)
{
Application.LoadLevel(LevelIndex);
return;
}
Good luck!
Answer by buzzhead1994 · Jan 28, 2013 at 08:40 AM
Thank you so much, just applied this to my code, worked fine, my highest praise goes your way right now!
Your answer
