赞
踩
这里是2020年3月20日
使用unity2020时,导入unity官方资源包Standard Assets出错了
然后试了试2019、2018的版本,居然都不行
unity2017倒没问题
我惊了,官方都没发现这个bug吗
仔细看了看Console,知道哪里出问题了
\Assets\Standard Assets\Utility\ForcedReset.cs
和
\Assets\Standard Assets\Utility\SimpleActivatorMenu.cs
出错了,大概是因为新版的unity没有GUITexture这类库了吧
把ForcedReset.cs的GUITexture修改为UnityEngine.UI.Image
SimpleActivatorMenu.cs的GUITexture修改为UnityEngine.UI.Text
再运行时,就没有问题了
也就是说,把ForcedReset.cs改为
using System; using UnityEngine; using UnityEngine.SceneManagement; using UnityStandardAssets.CrossPlatformInput; [RequireComponent(typeof (UnityEngine.UI.Image))] public class ForcedReset : MonoBehaviour { private void Update() { // if we have forced a reset ... if (CrossPlatformInputManager.GetButtonDown("ResetObject")) { //... reload the scene SceneManager.LoadScene(SceneManager.GetSceneAt(0).name); } } }
把SimpleActivatorMenu.cs改为
using System; using UnityEngine; namespace UnityStandardAssets.Utility { public class SimpleActivatorMenu : MonoBehaviour { // An incredibly simple menu which, when given references // to gameobjects in the scene public UnityEngine.UI.Text camSwitchButton; public GameObject[] objects; private int m_CurrentActiveObject; private void OnEnable() { // active object starts from first in array m_CurrentActiveObject = 0; camSwitchButton.text = objects[m_CurrentActiveObject].name; } public void NextCamera() { int nextactiveobject = m_CurrentActiveObject + 1 >= objects.Length ? 0 : m_CurrentActiveObject + 1; for (int i = 0; i < objects.Length; i++) { objects[i].SetActive(i == nextactiveobject); } m_CurrentActiveObject = nextactiveobject; camSwitchButton.text = objects[m_CurrentActiveObject].name; } } }
大概是因为这个bug太简单了以至于官方没当回事吧hhhh
不过对于新手来说确实是个麻烦
希望可以帮到你
——————————————————————————
——————————————————————————
这里是2020年8月1日
突然发现官方资源包Standard Assets更新了(不知道具体啥时候更新的),掌声祝贺官方修复了ForcedReset.cs的bug——ohhhhhhhhhhhhh
然而SimpleActivatorMenu.cs的bug依然坚挺,明明是同类型的bug,不知道官方是怎么做到只发现并修复了其中一个bug而另一个完全察觉不到的
文件路径还是老地方:
\Assets\Standard Assets\Utility\SimpleActivatorMenu.cs
目标:修改SimpleActivatorMenu.cs脚本
1、直接将文件的GUIText替换为UnityEngine.UI.Text
修改前:
public GUIText camSwitchButton;
修改后:
public UnityEngine.UI.Text camSwitchButton;
2、在文件引用UnityEngine.UI,然后将文件的GUIText替换为Text
修改前:
using System;
using UnityEngine;
…………其他代码…………
public GUIText camSwitchButton;
修改后:
using System;
using UnityEngine;
using UnityEngine.UI;
…………其他代码…………
public Text camSwitchButton;
两种方法没有本质的区别,主要是讲给新手听
实在不懂的,这里贴出修改后的完整代码
using System; using UnityEngine; using UnityEngine.UI; #pragma warning disable 618 namespace UnityStandardAssets.Utility { public class SimpleActivatorMenu : MonoBehaviour { // An incredibly simple menu which, when given references // to gameobjects in the scene public Text camSwitchButton; public GameObject[] objects; private int m_CurrentActiveObject; private void OnEnable() { // active object starts from first in array m_CurrentActiveObject = 0; camSwitchButton.text = objects[m_CurrentActiveObject].name; } public void NextCamera() { int nextactiveobject = m_CurrentActiveObject + 1 >= objects.Length ? 0 : m_CurrentActiveObject + 1; for (int i = 0; i < objects.Length; i++) { objects[i].SetActive(i == nextactiveobject); } m_CurrentActiveObject = nextactiveobject; camSwitchButton.text = objects[m_CurrentActiveObject].name; } } }
希望可以帮到你
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。