I’m new to unity webgl,the below code works well in windows desktop unity (in output i get “File Found”), but in javascript(webgl) it doesn’t work.
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class checkPath : MonoBehaviour {
// Use this for initialization
void Start ()
{
string filePath = "D:/testFile.txt";
Debug.Log("Looking for file: " + filePath);
if (File.Exists(filePath))
{
Debug.Log("File Found");
}
else Debug.Log("File not Found");
}
// Update is called once per frame
void Update () {
}
}
steps to reproduce the message:
- create a empty unity project.
- attach above script to any gameobject.
- build the project to webgl
- open the generated html file
note: i tried running the html file from vscode server still it shows “File not Found” in browser console(both Firefox and Chrome)
below is the output from browser console
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)
File not Found
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)```
i am using unity 2017.4.12f1 i had tried with unity 2019 still getting same message
**Update**: i tried copying testFile.txt to build folder and in TemplateData folder as well.
in code i added
```if (File.Exists("file:///testFile"))
if (File.Exists("/testFile"))
if (File.Exists("testFile"))```
none of these returns true in js (browser console)!