はじめに
こんにちは、suzukiです。本日はunityのStandard AssetsをImportした際に、発生する。エラーの対処方法についてまとめました。
Standard Assetsのエラー
Unityの3Dアプリケーションを作るにあたり必要になる機能が色々含まれています。
ThirdPersonControllerにはよくお世話になりました。
最後のUpdateはApr 8, 2020となっており、メンテナンスがされていないません。
そのためGUI Textという旧UIコンポーネントを利用しており、インポートを行った際に下記のエラーが発生します。
Assets/Standard Assets/Utility/SimpleActivatorMenu.cs(11,16): error CS0619: ‘GUIText’ is obsolete: ‘GUIText has been removed. Use UI.Text instead.’
修正方法
コンソールでているエラーをダブルタップすることでエラーの出ているスクリプトが開きます。
SimpleActivatorMenu
/Assets/Standard Assets/Utility/SimpleActivatorMenu.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using System; using UnityEngine; #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 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; } } } |
修正が必要な内容は下記の2点です。
public GUIText camSwitchButton;をpublic Text camSwitchButton;に変更
using UnityEngine.UI;の追加
変更を行なったコードは下記
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | using System; using UnityEngine; using UnityEngine.UI;//Fixed #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;//Fixed 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; } } } |
さいごに
使用されることの多いライブラリなので、メンテナンスされて欲しいですね。
とはいえ最低限の修正を使う側もできることは大事だと思うので、エラー発生した際に落ち着いて対応していきたいです。