Unity打開網頁問題

對於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/");
    }

}

 

Web版本:Application.ExternalEval("window.open('http://math.xpu.owvlab.net/virexp/s/exp/20177261.exe','_self')");來解決,_self的意思是在當前頁面打開。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章