c#小白寻求帮助

weixin_42049399 2018-04-23 04:13:07
'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);’
希望各位可以帮忙我解决一下,给点思路。
...全文
624 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaotomo 2018-04-25
  • 打赏
  • 举报
回复
未将对象引用到实例 一个对象还没有实例化,就去读取它的属性或方法,就会报这个错 具体你这里,就是transform对象没有实例化
hhhhha123 2018-04-25
  • 打赏
  • 举报
回复
有个Null
xuzuning 2018-04-23
  • 打赏
  • 举报
回复
您知道 Object reference not set to an instance of an object 的中文意思吗?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧