Currently opening a link through my game opens the link in the very same interface. I want it to open on a new tab. I tried researching plugins and whatnot so that a .jslib file interacts with the Unity project, but am having issues with that too. I'm new to this interaction so I'm also having problems finding the Plugin Inspector itself.
Currently, my code does this:
private void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
Application.OpenURL("www.google.com");
}
}
So this opens the link on the same browser. I'm trying to make it so when the user hits the return key, they open that link on to a new browser.
Any help is appreciated!
One correct way is using .jslib file
Assets/plugins/plugin.jslib
var plugin = {
OpenNewTab : function(url)
{
url = Pointer_stringify(url);
window.open(url,'_blank');
},
};
mergeInto(LibraryManager.library, plugin);
Your C# script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
public class OpenURL : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void OpenNewTab(string url);
public void openIt(string url)
{
#if !UNITY_EDITOR && UNITY_WEBGL
OpenNewTab(url);
#endif
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
openIt("www.wateverurluwant.com");
}
}
}