Ok, this is driving me bonkers. I have searched the forums, but can't find anything that addresses my issue, so here goes.
I'm trying to import a simple text file that describes the height of objects that I want to construct. I had this working completely using monoscript, but since moving to c# I have not been able to import this file, though I have tried implementing several solutions after my own did not work.
The text file holds strings of numbers that I use to determine the scale of Primitives which I am instantiating. My instantiation code works, I just can't load this text file and build using the data it gives me. I have tried placing the asset in various locations, to no avail.
Please let me know what I'm doing wrong. I'm new to c#, so be gentle ;)
using UnityEngine;
using System;
using System.Collections;
using System.IO;
public class LoadLevel : MonoBehaviour {
//the level as described in a text file
public static string[] dataLines;
public static int k;
public static string[] GetLines () {
ArrayList lines = new ArrayList();
string line;
TextAsset textFile = (TextAsset)Resources.Load("text", typeof(TextAsset));
System.IO.StringReader textStream = new System.IO.StringReader(textFile.text);
bool match = false;
while((line = textStream.ReadLine()) != null) {
lines.Add(line);
}
textStream.Close();
if (lines.Count > 0) {
return (string[])lines.ToArray(typeof(string));
}
return new string[0];
}
public static void Start(){
Debug.Log("LoadLevel Start Got Called!");
dataLines = GetLines();
Debug.Log(dataLines.Length);
... ... etc
The error I'm getting is
NullReferenceException: Object reference not set to an instance of an object LoadLevel.GetLines () (at Assets\Standard Assets\Scripts\LoadLevel.cs:20) LoadLevel.Start () (at Assets\Standard Assets\Scripts\LoadLevel.cs:37) Manager.Awake () (at Assets\Standard Assets\Scripts\Manager.cs:30)
I'm hoping this is something simple that I'm just not seeing or that my head is not wrapping properly around.
Any and all help welcome.
Cheers,
S.