对于PC端而言:Application.OpenURL(pathURL);(pathURL为网址)
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class Test : MonoBehaviour
{
public static Process C;
void OnGUI()
{
if (GUI.Button(new Rect(50, 50, 100, 30), "百度"))
{
// Application.OpenURL("https://www.baidu.com/");
CallWeb();
}
if (GUI.Button(new Rect(200, 50, 100, 30), "关闭"))
{
//这个地方并不能关闭打开的浏览器,错误显示为:SystemException: No process to kill.
C.Kill();
}
}
void CallWeb()
{
//可以自己选择浏览器,也可以用系统设置的默认浏览器,默认浏览器就不需要传入:"IExplore.exe"这个参数
// C = System.Diagnostics.Process.Start("IExplore.exe", "https://www.baidu.com/");
C = System.Diagnostics.Process.Start("https://www.baidu.com/");
}
}
修改线------------------------------------------------------------------------------------------------------------------------------------
上面C.Kill();这句话不能关闭打开的浏览器理解有点偏差。
首先,如果我在这里进程调用的时候,指定了浏览器,并且这个浏览器是没有打开的,那么你就可以Kill()掉这个进程,如果不指定浏览器如下:
System.Diagnostics.Process.Start( "https://www.baidu.com/");
那么就Kill()不了这个进程。
还有就是指定了浏览器的这个浏览器没打开任何网页,比如我指定了谷歌浏览器,但是我没打开谷歌浏览器,那么我在Kill()的时候也是能Kill()的。但是如果我用谷歌浏览器打开了一个网页,之后再调用System.Diagnostics.Process.Start("Chrome.exe", "https://www.baidu.com/");来开百度网页,那么这个时候我们就不能Kill()掉整个谷歌浏览器了,因为浏览器不知道我们这个进程是要关闭所有网页,还是要关闭我们打开的百度网页。
Web版本:Application.ExternalEval("window.open('http://math.xpu.owvlab.net/virexp/s/exp/20177261.exe','_self')");来解决,_self的意思是在当前页面打开。