c# - 构建到 android 后对象引用未设置为对象的实例
问题描述
我有一些错误,我不知道为什么在我的游戏中添加了一些本地化系统后,在游戏中转为空引用
这是我的 GameManager 脚本,我想我已经在统一编辑器中完成了对象引用,但是在构建到 android 之后,该对象变为空引用
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();
}
解决方案
将你的起始块放入 try catch
例如。:
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);
}
StackTrace
porperty 应该告诉你你的空引用发生在哪一行。
要在发布模式下启用此功能,请检查:Display lines number in Stack Trace for .NET assembly in Release mode
推荐阅读
- c - 使用来自 C 应用程序的 db2 CLI/ODBC 连接更新表错误?
- angular - 为什么使用异步过滤器会导致无休止的请求?
- angular - 如何使用 Angular 6 将 json 对象数组绑定到 angular-dual-listbox?
- devexpress - LookUpEdit 中的 DevExpress GridView
- php - PHP 7:使用 XADES-BES 签署 XML 文档
- android - monekeyrunner 无法返回“getProperty”和“getSystemProperty”的值
- angular - 如何在 ngFor 中删除元素后为所有元素设置动画
- c# - 在嵌套类中手动调用模型状态验证失败
- javascript - 如何使用 Node.js 在 Azure Application Insights 中禁用采样
- ios - 如何在swift 4中使用google api计算两个位置之间的距离