- Home /
The question is answered, right answer was accepted
Loading Scene on a series of events
Hello people of Earth and Mars.
I am making my Game Menu - I am actually making it to improve my knowledge on scripting so far I am doing great! However I have ran into a problem that the internet has no answer for and I have spent about 6 hours straight and still can not find an answer for.
So here is my problem:
I want a level/scene ("MainTerrainScene") to be loaded when a series of events happen. In this case the series of events are. When the cursor (DefaultMouse) Enters the text "New Game" (Box Collider : 3D Text) and whilst inside the text you click the left mouse button; A new scene called "MainTerrainScene" will be loaded.
I have tried everything I know of and the script works fine when the function is update and not "OnMouseEnter" however therefore the cost of not having the mouse to enter and then click is paid.
Here is my current script:
function OnMouseEnter()
{
if
(Input.GetMouseButtonDown(0))
{
Application.LoadLevel("MainTerrainScene");
}
}
The Code is in JavaScript.
Thanks for your time in reading hopefully you will have an answer for me :)
Answer by fafase · Jun 08, 2013 at 02:58 PM
Your 3D text has a colliderso you can use Raycast and Input.GetMouseButton(0)
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
Answer by GabrielSmith · Jun 08, 2013 at 02:35 PM
Why don't you use the OnMouseDown function to load the scene? This function is called when the mouse clicks over a Collider or a GUI, exactly what you want:
function OnMouseDown () {
Application.LoadLevel("MainTerrainScene");
}
I will thumb this up, however it is not what I am looking for. I know what you mean, but it would mean making a new script as all the inputs are attacched in one script
You wouldn't need to create another script. Just change the On$$anonymous$$ouseEnter function to On$$anonymous$$ouseDown and when you click over the object, the scene will be loaded.
@Edit: Oh, I guess i understand what you said. You have only one script, and using On$$anonymous$$ouseDown would need to create other script. But the same applies to On$$anonymous$$ouseEnter. You'll have to do what the bellow comment says: use Raycast and InputGet$$anonymous$$ouseButton(0).
Follow this Question
Related Questions
Load Scene 1 Answer
Random level select 1 Answer
Input.GetMouseButton on multiple objects 1 Answer
Load level after Image Sequence 0 Answers
Need to link a button to next level 1 Answer