I was trying to read a .txt located in a subfolder of my assets folder, I tried a couple of ways to do so, but I always get the same error:
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.IO;
public class DialogosControl : MonoBehaviour
{
public string Script;
StreamReader reader;
string[] arr;
string directory;
// Start is called before the first frame update
void OnEnable()
{
directory = "Assets/Dialogos";
Debug.Log(directory);
if (Directory.Exists(Path.GetDirectoryName(directory))) {
reader = new StreamReader(directory+"/"+Script);
}
else
{
Debug.Log("No existe el fichero");
}
}
// Update is called once per frame
void Update()
{
while (!reader.EndOfStream)
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
string line = reader.ReadLine();
arr = line.Split('&');
GameObject.Find("Character").GetComponent<TextMeshProUGUI>().text = arr[0];
GameObject.Find("Text").GetComponent<TextMeshProUGUI>().text = arr[1];
}
}
}
}
Thanks in advance.