Hello, I am very new to unity and Im trying to load and read a text file aswell as some other stuff within my script. The code for this script is below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
private GameObject Target;
void Start()
{
Target = GameObject.Find("Itemtext");
Debug.Log(Target.name);
}
}
public class TextFileLoader : MonoBehaviour
{
void Start()
{
// Move the resource loading code to Start() method
LoadTextFile();
Debug.Log("Perknames Loaded");
}
void LoadTextFile()
{
TextAsset textFile = Resources.Load<TextAsset>("Perknames");
if (textFile != null)
{
string fileContent = textFile.text;
Debug.Log(fileContent);
string[] stringArray = fileContent.Split(',');
Debug.Log(stringArray[0]);
List<string> stringList = new List<string>(stringArray);
foreach (string str in stringList)
{
Debug.Log(str);
}
}
else
{
Debug.LogError("Failed to load text file.");
}
}
}
Can someone please help me understand why my second Monobehaviour isnt getting called? I am having a hard time understanding this. And before you say it, yes this script is attatched to a gameobject. The first Monobehaviour is running fine.
Thank you for your time.