初心者用でも理解できるように学ぶ、Blender2.8/ゲーム開発/アニメ/漫画/趣味のなんでもサイト

ナマケモノにも分かるまなぶろぐ

Unity2019

【Unity2019】Standard Assetsでエラーが出た時の対処方

更新日:

unity2019.4.1f1でUnity Asset Store から Standard Assets (for Unity 2017.3)をインストールすると以下エラーが表示されます。

【エラー内容】
Assets\Standard Assets\Utility\SimpleActivatorMenu.cs(11,16): error CS0619: 'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'

【原因】
「GUITexture」が利用不可となった為です。

【対応方法】
インストールしたStandard Assets内のソースで
・ForcedReset.cs:「GUITexture」を「Image」のコードに変更。
・SimpleActivatorMenu.cs:「GUIText」を「Text」のコードに変更。

【修正方法】
「ForcedReset.cs」「SimpleActivatorMenu.cs」を修正します。

※修正方法は以下のコードを全コピーして貼りなおすと簡単です。

■「ForcedReset.cs」の修正

using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.UI; // 追加
[RequireComponent(typeof (Image))] // 変更 GUITexture -> 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;

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; // 変更 GUIText -> Text
        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;
        }
    }
}

-Unity2019

Copyright© ナマケモノにも分かるまなぶろぐ , 2024 All Rights Reserved Powered by STINGER.