C# 对象引用未设置为生成到android后的对象实例
我有一些错误,我不知道为什么在我的游戏中添加了一些本地化系统后,在游戏中会出现空引用 这是我的GameManager脚本,我想我已经在unity editor中使用了一个对象引用,但是在构建到android之后,这个对象变成了空引用C# 对象引用未设置为生成到android后的对象实例,c#,unity3d,C#,Unity3d,我有一些错误,我不知道为什么在我的游戏中添加了一些本地化系统后,在游戏中会出现空引用 这是我的GameManager脚本,我想我已经在unity editor中使用了一个对象引用,但是在构建到android之后,这个对象变成了空引用 private void Start() { LM = FindObjectOfType<LocalizationManager>(); audioManager = FindObjectOfType<AudioManager&g
private void Start()
{
LM = FindObjectOfType<LocalizationManager>();
audioManager = FindObjectOfType<AudioManager>();
questionManager = FindObjectOfType<_questionManager>();
LevelSelect = FindObjectOfType<SelecLevel>();
Select = FindObjectOfType<_CharacterSelect>();
sliderChanges = FindObjectOfType<SliderChanges>();
onlepel = LevelSelect.levelIndex + 1;
IndexLevel = LevelSelect.levelIndex;
getPlayerData();
Timecount = GameObject.FindGameObjectWithTag("TimeCount");
if (LM.Bahasa)
{
category = GameObject.Find("QuestionManagerIndonesia").GetComponent<_questionManager>().category;
}
else
{
category = GameObject.Find("QuestionManagerEnglish").GetComponent<_questionManager>().category;
}
moneyAmount = PlayerPrefs.GetFloat("MoneyAmount");
if (unansweredQuestion == null || unansweredQuestion.Count == 0)
{
thisQuestions = category[IndexLevel].questions;
unansweredQuestion = new List<Question>(thisQuestions);
TrueAnswerText.text = "CORRECT";
FalseAnswerText.text = "WRONG!";
//unansweredQuestion = new List<Question>(questions);
}
if (TrueAnswerText != null)
TrueAnswerText.text = "CORRECT";
if (FalseAnswerText != null)
FalseAnswerText.text = "WRONG!";
TrueCount = 0;
if (FactText != null)
setCurrentQuestion();
}
private void Start()
{
LM=FindObjectOfType();
audioManager=FindObjectOfType();
questionManager=FindObjectOfType();
LevelSelect=FindObjectOfType();
Select=FindObjectOfType();
sliderChanges=FindObjectOfType();
onlepel=LevelSelect.levelIndex+1;
IndexLevel=LevelSelect.levelIndex;
getPlayerData();
Timecount=GameObject.FindGameObjectWithTag(“Timecount”);
如果(长文巴哈萨语)
{
category=GameObject.Find(“QuestionManagerIndonesia”).GetComponent().category;
}
其他的
{
category=GameObject.Find(“QuestionManagerEnglish”).GetComponent().category;
}
moneyAmount=PlayerPrefs.GetFloat(“moneyAmount”);
if(unansweredQuestion==null | | unansweredQuestion.Count==0)
{
thisQuestions=类别[IndexLevel]。问题;
未回答问题=新列表(此问题);
TrueAnswerText.text=“正确”;
false answertext.text=“错误!”;
//未回答问题=新列表(问题);
}
if(TrueAnswerText!=null)
TrueAnswerText.text=“正确”;
if(FalseAnswerText!=null)
false answertext.text=“错误!”;
TrueCount=0;
if(FactText!=null)
setCurrentQuestion();
}
将您的起始区块放入试一试
例如:
StackTrace
porperty应该告诉您null引用发生在哪一行
要在发布模式下启用此功能,请选中此项:well。。它发生在这里
LevelSelect.levelIndex
或这里category[IndexLevel]。问题
。。。在何处以及如何初始化类别
?或者在TrueAnswerText.text=
和falsanswertext.text=
-在null
检查之前发生的那些…谢谢,我发现了问题,因为我有一个对象的实例,并且变成了静态,所以类别
无法加载2个引用<代码>静态管理器实例代码>if(instance!=null){Destroy(gameObject);}else instance=this;DontDestroyOnLoad(游戏对象)代码>谢谢,我发现了这个问题,这是因为我有一个对象的实例,它变成了静态的,所以类别
无法加载2个引用。所以我删除了它,只把DontDestroyOnload
static\u questionManager实例放进去代码>if(instance!=null){Destroy(gameObject);}else instance=this;DontDestroyOnLoad(游戏对象)代码>
try
{
// A class that has an int field called var
Test asd = null;
// whops null reference
int var = asd.var;
}
catch (NullReferenceException ex)
{
Console.WriteLine(ex.StackTrace);
}