2 qq 26470013 qq_26470013 于 2016.03.24 03:16 提问

unity3d脚本添加时出现错误

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.TreeViewDragging.DragElement (UnityEditor.TreeViewItem targetItem, Rect targetItemRect, Boolean firstItem) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/GUI/TreeView/TreeViewDragging.cs:201)
UnityEditor.TreeView.HandleUnusedMouseEventsForNode (Rect rect, UnityEditor.TreeViewItem item, Boolean firstItem) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/GUI/TreeView/TreeView.cs:304)
UnityEditor.TreeView.OnGUI (Rect rect, Int32 keyboardControlID) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/GUI/TreeView/TreeView.cs:408)
UnityEditor.SceneHierarchyWindow.DoTreeView

2个回答

herozhangbz
herozhangbz   2016.03.24 16:17

201行,对象的引用未设置到对象的实例。应该是引用的时候可能没有这个实例或者物体,引用出错了。304不知道,看着像UnityEditor.TreeView.HandleUnusedMouseEventsForNode函数后面的Rect rect, UnityEditor.TreeViewItem item, Boolean firstItem三个参数你弄错了。408跟304差不多UnityEditor.TreeView.OnGUI函数后面两个参数你检查检查。

herozhangbz
herozhangbz 回复skyblue_2012: 可能跟vs还有u3d的版本有关系。我是用这个实现的GameObject.Find("Canvas/zt").GetComponent(UnityEngine.UI.Text).text="射弹计数:"+sds+"销毁数:"+xhs;
一年多之前 回复
herozhangbz
herozhangbz 回复skyblue_2012: 你是做的语谭老师的练习吧。看看你的物体是叫wenzi么
一年多之前 回复
herozhangbz
herozhangbz 回复skyblue_2012: 你的对象是空的呗
一年多之前 回复
qq_26470013
qq_26470013 这一行代码是这样的,gameObject.Find("wenzi").GetComponent(GUIText).text="射弹数:" + sdshu;
一年多之前 回复
qq_26470013
qq_26470013 那个解决了。现在有一个文嗯的问题,NullReferenceException: Object reference not set to an instance of an object sheji.Update () (at Assets/sheji.js:25)
一年多之前 回复
oiu1010110
oiu1010110   2016.03.25 00:17

看第一个错误的意思先

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!