可以使用以下代码:

using UnityEngine;
using System.Collections;

public class RequestExample : MonoBehaviour {

    IEnumerator Start () {
        // 请求网址
        string url = "http://www.example.com";
        UnityWebRequest www = UnityWebRequest.Get(url);
        yield return www.SendWebRequest();

        if (www.isNetworkError || www.isHttpError) {
            Debug.Log(www.error);
        } else {
            Debug.Log("请求成功!");
        }

        // 退出Unity
        Application.Quit();
    }
}

将脚本挂载在一个GameObject上,并在命令行中使用以下命令进行批处理:

Unity.exe -batchmode -executeMethod RequestExample.Start

这将启动Unity,执行脚本中的Start方法,请求网址,成功后退出Unity。

在unity的batchmode中使用unitywebequest请求网址url在成功后退出unity

原文地址: https://www.cveoy.top/t/topic/IMf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录