I have a javascript code that I just want to be run when a button is clicked. Is there any way to do that?
You can do it with a GUI Button…
Try some code something like this:
function OnGUI(){
if(GUI.Button(Rect(10,10,50,50), "Click to load scene")){
Application.LoadLevel("levelToLoadWhenButtonClicked");
}
}
You can just change the position of the button and the text… If you know about GUI Buttons, then you’ll know how to do that, if not, then for your information, the two 10’s specify the height and width…
Then just change levelToLoadWhenButtonClicked
to the name of the scene that you want to load!!!
Here is the GUI.Button
scripting reference for you: http://unity3d.com/support/documentation/ScriptReference/GUI.Button.html
Hope this helps you, and if you need more help, then feel free to comment back!!!
-Grady