【持续更新中】Unity常见问题及其解决
0@toc
导出游戏时需要选择空的文件夹否则会出现以下错误
错误 error CS0103: The name ‘gameobject’ does not exist in the current context
解决 脚本中获取游戏对象使用gameObject。
注Debug.Log(“”);表示调试时输出引号中的内容。
错误 error CS1061: ‘Vector2’ does not contain a definition for ‘X’ and no aessible extension method ‘X’ aepting a first argument of type ‘Vector2’ could be found (are you missing a using directive or an assembly reference?)
解决 脚本中获取游戏对象的位置使用x、y、z。
①请确保正确输入了成员名。
②如果有权修改此类,则可以添加缺少的成员并实现它。
③如果没有修改此类的权限,则可以添加扩展方法。
问题 Unity怎么点击都没反应,但又不是卡住了,考虑可能是代码写的不当,出现了死循环代码。
解决 先用任务管理器将Unity关闭,再仔细检查代码,确定逻辑无误后再调试运行。
检查代码或者使用强制转换。
CS1656错误: 无效赋值错误检查代码的赋值是否正确。
NullReferenceException空指针错误,Object并没有作为一个对象的实例错误NullReferenceException: Object reference not set to an instance of an object
解决对象需要实例化后才能使用。
深刻的教训有次为了图方便,对象名是复制的,多复制了一个空格,导致一直报没有实例化的错误,找了两天才找到。இ௰இ
错误UnassignedReferenceException: The variable XXXX of XXXXX has not been assigned.
解决脚本中写明该变量为public,而在Inspector窗口中却未给其赋值,在Inspector窗口赋值即可。
错误Scene ‘WhacAMole’ couldn’t be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
To add a scene to the build settings use the menu File->Build Settings…
解决选择 File->Build Settings->Add open scenes
错误IndexOutOfRangeException: Index as outside the bounds of the array.
解决限制数组索引,使其不要越界。
错误ArgumentException: The Object you ant to instantiate is null.
解决在Inspector或Scripts中引用要实例化的对象。
错误ArgumentOutOfRangeException: Index as out of range. Must be non-negative and less than the size of the collection.
解决注意访问集合元素时,索引是否超出了范围。
错误arning CS0108: ‘MouseDrag.camera’ hides inherited member ‘Component.camera’. Use the ne keyord if hiding as intended.
解决一在变量声明处添加ne关键字。
解决二改变变量的名字避免产生混淆。
错误InvalidCastException: Specified cast is not valid.
解决Unity中AudioSource使用Resources.Load()方法加载。
错误FormatException: Input string as not in a correct format.
解决检查读取到的值的格式。
错误StackOverfloException: The requested operation caused a stack overflo.
解决检查程序中是否存在递归调用,导致程序卡死。
提示There are 2 audio listeners in the scene. Please ensure there is alays exactly one audio listener in the scene.
解决一般新创建一个场景后,在Main Camera中都有一个Audio Listener组件,用于监听场景中是否有音频的播放。如果需要场景中的音乐不随场景的切换而重置,需要场景中只有一个Audio Listener,删除一个即可。
错误Setting the parent of a transform hich resides in a Prefab Asset is disabled to prevent data corruption (GameObject: ‘AudioCube’).
//加载预制体 GameObject audioCube = Resources.Load("AudioCube"); //初始化预制体 GameObject gameObject = Instantiate(audioCube, ne Vector3(1, 0, 0), Quaternion.identity); //设置父物体 audioCube.transform.SetParent(AudioCubes.transform);
预想将使用预制体audioCube实例化的物体的父物体设置为AudioCubes,如上方法会导致设置不成功。
解决
使用Instantiate的重载方法直接把物体的父物体设置好就不会有如上问题
//加载预制体 GameObject audioCube = Resources.Load编辑器布局无法完全加载问题("AudioCube"); //初始化预制体 GameObject gameObject = Instantiate(audioCube, ne Vector3(1, 0, 0), Quaternion.identity,AudioCubes.transform);
提示The editor layout could not be fully loaded, this can happen hen the layout contains EditorWindos not available in this project
UnityEditor.WindoLayout:LoadDefaultWindoPreferences()
解决建立的项目名称是中文名,改成英文即可。
问题当把prefab从当前scene中删除之后,再添加到一个scene中时,unity无法找到在第一个scene中添加的gameobject。
解决把该gameobject也制成prefab,即可以让该gameobject成为prefab的孩子。
没有显示在Console中的编译错误可能问题
- 函数引用没加()
- 用到了包,没有用using引用
空调维修
- 温岭冰箱全国统一服务热线-全国统一人工【7X2
- 荆州速热热水器维修(荆州热水器维修)
- 昆山热水器故障码5ER-昆山热水器故障码26
- 温岭洗衣机24小时服务电话—(7X24小时)登记报
- 统帅热水器售后维修服务电话—— (7X24小时)登
- 阳江中央空调统一电话热线-阳江空调官方售后电
- 乌鲁木齐阳春燃气灶厂家服务热线
- 珠海许昌集成灶售后服务电话-全国统一人工【
- 乌鲁木齐中央空调维修服务专线-乌鲁木齐中央空
- 新沂热水器故障电话码维修-新沂热水器常见故障
- 诸城壁挂炉24小时服务热线电话
- 靖江空调24小时服务电话-——售后维修中心电话
- 空调室外滴水管维修(空调室外排水管维修)
- 九江壁挂炉400全国服务电话-(7X24小时)登记报修
- 热水器故障码f.22怎么解决-热水器f0故障解决方法
- 营口热水器售后维修服务电话—— 全国统一人工