Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么GUI组件过时了?_C#_Unity3d_User Interface - Fatal编程技术网

C# 为什么GUI组件过时了?

C# 为什么GUI组件过时了?,c#,unity3d,user-interface,C#,Unity3d,User Interface,我目前正在Unity3D中重拍恐怖大厅。我得到了代码,但有两个错误: Assets\Standard Assets\Utility\ForcedReset.cs(6,27): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.' 我尝试用错误中提供给我的项替换它们,但仍然出现错误,表示找不到名称空间名称UI。我还不习惯团结,所以我需要一些帮助 以下是ForcedR

我目前正在Unity3D中重拍恐怖大厅。我得到了代码,但有两个错误:

Assets\Standard Assets\Utility\ForcedReset.cs(6,27): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.'
我尝试用错误中提供给我的项替换它们,但仍然出现错误,表示找不到名称空间名称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);
        }
    }
}
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;
        }
    }
}
下面是
SimpleActivatorMenu.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);
        }
    }
}
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;
        }
    }
}
使用系统;
使用UnityEngine;
命名空间UnityStandardAssets.Utility
{
公共类SimpleActivatorMenu:单行为
{
//一个非常简单的菜单,当提供参考时
//在场景中添加游戏对象
公共吉他文本开关按钮;
公共游戏对象[]对象;
私有int m_CurrentActiveObject;
私有void OnEnable()
{
//活动对象从数组中的第一个开始
m_CurrentActiveObject=0;
camSwitchButton.text=对象[m_CurrentActiveObject]。名称;
}
公共无效NextCamera()
{
int-nextactiveobject=m_CurrentActiveObject+1>=objects.Length?0:m_CurrentActiveObject+1;
for(int i=0;i

有问题吗?

由于可组合性和其他一些问题,吉他文本和其他元素已从较新版本的Unity中删除

修复GUI文本

确保在代码中导入以下语句行:-

using UnityEngine.UI;

using UnityEngine.UI;

然后,简单地从

 public GUIText camSwitchButton;

修复了GUI纹理的问题

此修复程序在其他文件上给了我一些警告,但工作正常!它可能会在即将发布的Unity更新中修复

确保在代码中导入以下语句行:-

using UnityEngine.UI;

using UnityEngine.UI;

然后,更改这行代码

[RequireComponent(typeof (GUITexture))]
对,

希望这有帮助!我已经检查过了,它工作正常,但只是给了我一些警告,我不在乎


但它会很好,并将在一些即将推出的Unity版本中修复

编译或运行此代码是否有某种输出?错误消息?
为什么GUI组件过时?
因为,正如错误所说,他们希望您改用新方法。
但它仍然存在问题。
问题是什么?这些消息意味着您正在使用的类库的作者已将
GuitTexture
GuitText
标记为过时,并建议您改用不同的类。像这样的替换不是插入式替换,您需要更新代码,这并不罕见。您的声明“我试图用错误中提供给我的项目替换它们,但仍然存在问题”是没有用的。我们猜不出你有什么问题。你收到错误信息了吗?如果是这样,在编译时还是在运行时?这应该是针对Unity项目的,而不仅仅是一个简单的程序。是的,程序中有两个错误,我还是Unity的新手,所以是的。谢谢你的邀请@理查德