Skip to main content

Excute JavaScript

Create your Unity Script

public class TestScript : MonoBehaviour
{
public EdgeCanvas m_edgeCanvas;

void ExcuteScript()
{
m_edgeCanvas.ExecuteScript("navigator.userAgent", (error, result) =>
{
if (error)
{
Debug.LogError("Excute Failed.");
}
else
{
Debug.Log(result);
}
});
}

void OnGUI()
{
if (GUILayout.Button("Excute"))
{
ExcuteScript();
}
}
}

script1

Click the Excute button, and Unity will receive the following message

script2

More usage methods

tip

console.log('hello') Echo Log

tip

document.body.clientWidth Get Body ClientWidth

tip

OnCustomFunction Return the result of a custom method