I create code and then attach it to a button within the OnClick() in the inspector which works for c sharp
but it doesn’t work for Javascript?
#pragma strict
function LoadScene (String level)
{
Application.LoadLevel(level);
}
Here is the C Sharp script which works…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayButton : MonoBehaviour {
public void changemenu(string scenename)
{
Application.LoadLevel(scenename);
}
}
When passing variables into Javascript, they must be declared like this
function LoadScene (level : String)
{
Application.LoadLevel(level);
}
the syntax of declaration is completely different to C#. your problem was because it doesn’t accept that input you should of had an error appear in your console log stating so.
Also, if you know the C# solution why try convert to JavaScript? there’s a lot more help online for C# than their is Javascript
Both Application.LoadLevel and Unity’s implementation of JS are deprecated. JS will have a soft removal in 2017.2 (next major release, can still compile JS but you won’t be able to create new JS scripts in the Unity UI). Application.LoadLevel will be removed in some future build, and was replaced by SceneManager.LoadScene back in 5.3 or so.
I’d suggest not starting any new projects using either.