unity设置外置文件,运行读取文件获取地址

直接放代码吧

 public static string url= "http://192.168.1.43:9100";
    //public static string url = "http://43.137.7.254:10028/server";
    private void Awake()
    {
        StartCoroutine(GetPath());
    }
    IEnumerator GetPath()
    {
        using (UnityWebRequest webRequest =UnityWebRequest.Get (Application.streamingAssetsPath +"/URLPath.txt"))
        {
            // 发送请求
            yield return webRequest.SendWebRequest();
            // 检查是否有错误
            if (webRequest.result != UnityWebRequest.Result.Success)
            {
                Debug.LogError("Error: " + webRequest.error);            
            }
            else
            {
                url = webRequest.downloadHandler.text;
                //Debug.Log("地址:" + url);          
                webRequest.Dispose();
              
            }
        }
    }

 

posted @ 2025-10-23 16:42  剑起苍穹  阅读(3)  评论(0)    收藏  举报
/*鼠标点击特效*/