?读取的文件路径上代码
string path = Path.Combine(Application.streamingAssetsPath, "data.txt"); //unity Editor,webgl 端 都可以读取
string path = Application.streamingAssetsPath + "/data.txt"; //unity Editor,webgl 端 都可以读取
//string path = "file://" + Path.Combine(Application.streamingAssetsPath, "data.txt"); //unity Editor可以读取,webgl 端 读取不到
//string path = "file://" + Application.streamingAssetsPath + "/data.txt"; //unity Editor可以读取,webgl 端 读取不到
//string path = @"file://" + Application.streamingAssetsPath + "/data.txt"; //unity Editor可以读取,webgl 端 读取不到
//string path = "file:///" + Application.streamingAssetsPath + "/data.txt"; //unity Editor可以读取,webgl 端 读取不到
读取方式
IEnumerator LoadTxt()
{
string path = Application.streamingAssetsPath + "/data.txt";
///第一种方式
WWW www = new WWW(path);
yield return www;
string data = www.text;
Debug.Log(data);
///第二种方式
UnityWebRequest request = UnityWebRequest.Get(path);
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.Log(request.error);
}
else
{
string data = request.downloadHandler.text;
Debug.Log(data);
}
}