I am trying to get my program to read the information of a game I created on Unity that I burned onto a CD-R. But whenever I do, I get the following error:
Unauthorized Access Exception: Access to the path “E:\GameInfo.xml” is denied.
Here’s the script (c-sharp) I am using just for those who want to investigate (script not done):
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class MenuGameReader : MonoBehaviour {
//The two slashes ("//") mean unused code or side notes.
public string url = "File:///E:/GameInfo.xml";
public string path = "E:/GameInfo.xml";
public GameObject Canvas;
public Text GameTitleText;
[System.Serializable]
public class ProgramInfo {
[XmlAttribute("name")] public string name = "";
}
IEnumerator CheckForNewData()
{
yield return new WaitForSeconds(2);
}
IEnumerator Start () {
Canvas = GameObject.Find("Canvas");
GameTitleText = GameObject.Find("GameTitle").GetComponent<Text>();
Debug.Log("Hello");
WWW w = new WWW(url);
yield return w;
Debug.Log(w.text);
//yield return StartCoroutine("CheckForNewData");
Debug.Log("Reading disk, please wait...");
yield return w;
print(w.isDone);
if(w.isDone){
var xmlSerializer = new XmlSerializer(typeof(ProgramInfo));
//FileStream stream = File.Open("E:/GameInfo.xml", FileMode.Open);
var stream = File.Open(path, FileMode.Open);
var deserializedGameInfo = xmlSerializer.Deserialize(stream) as ProgramInfo;
stream.Close();
ProgramInfo programinfo = deserializedGameInfo;
Debug.Log(programinfo);
}
if (!string.IsNullOrEmpty(w.error)){
Debug.Log(w.error);
}
yield return new WaitForSeconds(4);
}
}
I have never received this issue with the “WWW” method, which I used to load THE SAME FILE! All I’m trying to do is to get my program to display XML, does anyone know if I can load the text data from the XML file through the WWW method? (P.S. The XML file is a local file.) I can show you the XML file upon request if you need it for assisting my issue.
Before you ask, disabling the Real-Time Virus scan and running as an administrator DIDN’T work for me.