0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UnityにおけるThirdPesronCharactorのエラーに対策

Posted at

ThirdPersonCharactorを使おう

エラー内容

エラー文

ThirdPersonCharactorを使おうとしたところ次の様なエラーが出た。

Assets/Standard Assets/Utility/SimpleActivatorMenu.cs(11,16): error CS0619: 'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'

詰まるところ、
GUITextが消去されたから、代わりにUI.Textを使えということの様だ。

エラー内容

実際にプログラムを見てみると、

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;
        }

実際にはもっと続いているが、今回問題となる場所のみを取り出してきた。
次に、どこが問題なのかを調べた。

対処法

対処法を調べたところ、次のサイトに乗っていた。

要約すると、
上のプログラム中で、GUITextとなっている部分をTextに変えれば良いとのことだ。
また、それに付随して

Using UnityEngine.UI;

の一文も追加すると動いてくれるらしい。

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;
        }

Unityの方を確認すると、確かにエラーが消えていることが分かる。

蛇足

Using UnityEngine.UI;

の一文を追加しないと、

Assets/Standard Assets/Utility/SimpleActivatorMenu.cs(15,16): error CS0246: The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)

というエラーが出てくる。
つまり、Textが見つからないという感じなので、先の文を追加してあげる必要がある。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?