I'm using Unity 5 and mono develop for C# editing. I have one C# file that reads a CSV file and creates a string from the content within the CSV. I made this class a public class with a public string variable because I want to be able to access this string variable in another class. Here's the CSV Reader class:
using UnityEngine;
using System.Collections;
using System.IO;
public class ReadText : MonoBehaviour{
public TextAsset textFile; // drop your file here in inspector
public string text = "";
void Start(){
string text = textFile.text; //this is the content as string
Debug.Log(text);
}
}
This class works fine. I get the Debug.Log(text) output on the Unity console when I run it, as expected.
Here's the other class that I'm trying to access the ReadText class public text from:
public class CreateLevel : MonoBehaviour {
void Start () {
//First, access the text that was read into the ReadText Class (from CSV file)
//Find the object "Level Designer" that has the ReadText.cs script attached to it
GameObject designer = GameObject.Find("LevelDesigner");
//Get a component of the ReadText Class and assign a new object to it
ReadText CSVText = designer.GetComponent<ReadText>();
//Now you can access the public text file String
string levelString = CSVText.text;
print(levelString);
//Second, identify each individual text, line by line. As each text symbol is identified
//place the corresponding sprite on the allocated space in the game scene
//When the & symbol is encoutered, go to the next line
//do all this while there are text symbols, once we have the "!" symbol, we're done
print(text);
print("We're inside of CreateLevel Class! :C)");
}
}
The CreateLevel C# file is attached to an empty object in the scene. Unity runs with no issues but I'm not getting the output from the Debug.Log or print(text) command of this class so I'm missing something here. Any help will be great.