'Object reference not set to an instance of an object' 不懂怎么解决,我写这个是为了读取TXT文本中的角度数据至二维数组,然后每隔一段时间更改物体的角度,但是使用二维数组时出现了问题。小白不懂怎么解决。using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;
using System.Collections.Generic;
public class loadtest : MonoBehaviour
{
public TextAsset txtRawFile;
public Text uiText; public float timer = 1.0f;
public int z = 0; public float[,] spaces; private List<string> eachLine;
private string theWholeFileAsOneLongString; // Use this for initialization
void Start ()
{ theWholeFileAsOneLongString = txtRawFile.text; eachLine = new List<string>();
eachLine.AddRange(theWholeFileAsOneLongString.Split("\n"[0])); float[,] spaces = new float[eachLine.Count, 6]; // 获取整数数组 for (int i = 0; i < eachLine.Count; i++) { // 逐行转换
string st = eachLine[i]; // 取得一行 string[] nums = st.Split(new[] { ',' });
if (nums.Length != 6) {
Debug.Log ("Misforned input on line "+i+1);
}
for (int j = 0; j < Mathf.Min (nums.Length, 6); j++) {
float val;
if (float.TryParse (nums[j], out val))
spaces[i,j] = val;
else
spaces[i,j] = -1;
}
} }
void Update(){
timer -= Time.deltaTime;
if(timer<=0) {
transform.localEulerAngles = new Vector3 (0, 0,-spaces[z,0]*57);
Debug.Log (z);
timer = 1.0f;
z = z + 1;
}
}
}错误提示是这一句出现问题‘transform.localEulerAngles = new Vector3 (0, 0,-spaces[z,0]*57);’
希望各位可以帮忙我解决一下,给点思路。
using System.Collections;
using System.IO;
using UnityEngine.UI;
using System.Collections.Generic;
public class loadtest : MonoBehaviour
{
public TextAsset txtRawFile;
public Text uiText; public float timer = 1.0f;
public int z = 0; public float[,] spaces; private List<string> eachLine;
private string theWholeFileAsOneLongString; // Use this for initialization
void Start ()
{ theWholeFileAsOneLongString = txtRawFile.text; eachLine = new List<string>();
eachLine.AddRange(theWholeFileAsOneLongString.Split("\n"[0])); float[,] spaces = new float[eachLine.Count, 6]; // 获取整数数组 for (int i = 0; i < eachLine.Count; i++) { // 逐行转换
string st = eachLine[i]; // 取得一行 string[] nums = st.Split(new[] { ',' });
if (nums.Length != 6) {
Debug.Log ("Misforned input on line "+i+1);
}
for (int j = 0; j < Mathf.Min (nums.Length, 6); j++) {
float val;
if (float.TryParse (nums[j], out val))
spaces[i,j] = val;
else
spaces[i,j] = -1;
}
} }
void Update(){
timer -= Time.deltaTime;
if(timer<=0) {
transform.localEulerAngles = new Vector3 (0, 0,-spaces[z,0]*57);
Debug.Log (z);
timer = 1.0f;
z = z + 1;
}
}
}错误提示是这一句出现问题‘transform.localEulerAngles = new Vector3 (0, 0,-spaces[z,0]*57);’
希望各位可以帮忙我解决一下,给点思路。
一个对象还没有实例化,就去读取它的属性或方法,就会报这个错
具体你这里,就是transform对象没有实例化