Unity open external link

Asked

Viewed 737 times

2

By placing the Unity file on the page I cannot redeploy the action to another page. What happens is that the new page opens inside the "frame" for the Unity file.

using UnityEngine;
using System.Collections;

public class Urlazerecovelo : MonoBehaviour {

    void OnMouseDown ()
    {
        Application.OpenURL("https://www.google.pt");
    }
}

1 answer

4

Your question is not clear, but from what I understand you did a project on Unity3d, compiled for the web (that is, generated the version in Webgl), put it to run on a page of your, and then tested your code.

Well, in that case, your code won’t even work as you expect. According to the documentation from Application.OpenURL, it opens the URL in the default browser, but the result is not specified if the application is running in the browser. Still, I think it befitting him to open in the same frame in which the application is running.

If you want more control and make external interactions (with Javascript, for example), use the method Application.ExternalEval. Test your code like this, for example:

using UnityEngine;
using System.Collections;

public class Urlazerecovelo: MonoBehaviour
{
    void OnMouseDown()
    {
        Application.ExternalEval("window.open(\"https://www.google.pt\")");
    }
}

Still, interactions between your application and Javascript should be limited or reduced to a minimum. If you are making an effort to build an application on Unity, try to make the most important interactions on it, because only then can you get portability (that is, run on other platforms) which is just one of the strengths of this tool.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.