【发布时间】:2021-02-21 21:48:30
【问题描述】:
我的代码适用于一维数组,但是当我尝试制作一个二维数组时,我收到一条错误消息
错误信息:
NullReferenceException: Object reference not set to an instance of an object
这是我的代码:
public class NewBehaviourScript : MonoBehaviour
{
public CoreManager[] mng2 = new CoreManager[5];
public CoreManager[][] mng = new CoreManager[5][];
void Start()
{
//this code works fine
mng2[1].actual_words = new string[5];
mng2[1].actual_words[0] = "test 1 ";
Debug.Log(mng2[1].actual_words[0]);
//this code gives me the error message
mng[0][0].actual_words = new string[5]; // the error message is about this line
mng[0][0].actual_words[0] = "test 2 ";
Debug.Log(mng[0][0].actual_words[0]);
}
}
CoreManager 类:
public class CoreManager
{
[Tooltip("Write these words in actual sequence of the sentence")]
public string[] actual_words;
[Tooltip("Write these words in any sequence of the sentence")]
public string[] mixed_words;
}
【问题讨论】:
标签: c# arrays visual-studio unity3d object