- Home /
C# to Java Script Conversion
I have this line of code... What would it be in Java Script:
Application.LoadLevel("Character Generation");
I also would like to be able to click a text, and it would activate this. What would be the function... OnMouseClick?
Answer by Kmulla · Nov 11, 2012 at 09:44 PM
In the documentation you can see that the line of code that you provided, is exactly the same as used in javascript. (http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevel.html)
The text you want to click, is that GUI text? If that is the case, you would use the OnGUI function:
function OnGUI () {
if (GUI.Button (Rect (10,10,150,100), "Text"))
print ("You clicked the text!");
}
This creates a box with your text. If you don't like the box around your text, you can create a GUI Skin and remove the background under the menu Button and then assigning the GUI Skin to your button like this:
var myGUISkin : GUISkin;
function OnGUI () {
GUI.skin = myGUISkin;
if (GUI.Button (Rect (10,10,150,100), "Text"))
print ("You clicked the text!");
}
Documentation can be found here: http://docs.unity3d.com/Documentation/ScriptReference/GUI.Button.html?from=MonoBehaviour
Answer by Graham-Dunnett · Nov 11, 2012 at 09:43 PM
In Javascript that would be written as:
Application.LoadLevel("Character Generation");
Your answer
![](https://koobas.hobune.stream/wayback/20220613083711im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with conversion from javascript to c# 3 Answers
Multiple Cars not working 1 Answer
Converting variable from javascript to C# 2 Answers
Trying to convert this javascript code to C# 1 Answer
Distribute terrain in zones 3 Answers