1. The first method: use the URL to connect directly
Write this connection method when you need to connect, for example, write in the Button click event below; this way is to jump out of unity and open the browser
public void ConnectUrl()
{
Application.OpenURL("http://www.baidu.com");
}
2. The second method: use www to access the URL
VS shows that www is outdated.
This way is to jump out of unity and open the browser
public void ConnectUrl()
{
WWW www = new WWW("http://www.baidu.com");//外部HTML和本地HTML都可
Application.OpenURL(www.url);
}
3. The third method: use UnityWebRequest to access the URL
This way is to jump out of unity and open the browser
- browser HTML
//新版UnityWebRequest
public void ConnectUrl1()
{
UnityWebRequest unityWebRequest = new UnityWebRequest("https://www.csdn.net/");
Application.OpenURL(unityWebRequest.url);
}
- local HTML
//使用绝对路径
public void ConnectUrl1()
{
UnityWebRequest unityWebRequest = new UnityWebRequest("file:///F:/a/b/c/d/Assets/Vuplex/WebView/Documentation/index.html");
Application.OpenURL(unityWebRequest.url);
}
//使用相对路径
public void ConnectUrl2()
{
UnityWebRequest unityWebRequest = new UnityWebRequest(Application.dataPath + "/Resources/index.html");
Application.OpenURL(unityWebRequest.url);
}
- ./ is the current directory
- . ./ is the parent directory
- / is the root directory
Four, the fourth: use the Embedded Browser plug-in
This way is to open the URL in unity.
For details, see the use of the Embedded Browser plug-in.
Five, the fifth: use the UniWebView plug-in
This way is to open the URL in unity.
For details, see the use of the UniWebView plug-in.
Reference URL:
https://cloud.tencent.com/developer/article/1865441