我目前正在Unity3D中重新制作Dreadhalls。我得到了代码,但我有两个错误:
AssetsStandard AssetsUtilityForcedReset.cs(6,27): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.'
AssetsStandard AssetsUtilitySimpleActivatorMenu.cs(10,16): error CS0619: 'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'
我试着用错误中给我的项目替换它们,但仍然会出现错误,说找不到namespacee名称UI。我仍然不习惯团结,所以我需要一些帮助。
这是ForcedReset.cs
:的代码
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof (GUITexture))]
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 GUIText 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;
}
}
}
有问题吗?
GUIText和其他元素已从Unity的新版本中删除,原因是可组合性和其他一些问题!
修复GUI文本
确保您在代码中导入以下语句行:-
using UnityEngine.UI;
然后,只需从更改
public GUIText camSwitchButton;
至
public Text camSwitchButton;
已修复GUI纹理
这个修复程序在其他文件上给了我一些警告,但工作正常!它可能会在即将到来的Unity更新中被修复!
确保您在代码中导入以下语句行:-
using UnityEngine.UI;
然后,从此代码行更改
[RequireComponent(typeof (GUITexture))]
至,
[RequireComponent(typeof(Texture))]
希望这有帮助!我检查过了,效果很好,但只是给了我一些警告,我不在乎!
但它会很好,并将在一些即将到来的统一版本中得到修复!
固定
- 对于
ForcedReset.cs
文件,使用以下代码更改其内容:
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof(Texture))]
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;
using UnityEngine.UI;
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;
}
}
}