
前提・実現したいこと
Unityで特定の条件を満たしていたらinteractableをTrueにしボタンを押せるようにしたいです。
interactable(false)⇒指定アイテム入手⇒interactable(True)
発生している問題・エラーメッセージ
最初はオブジェクト参照がオブジェクト インスタンスに設定されていません。というNullがでており、他の方の質問を参考に書き直し下のコードになったのですが新しくエラーが発生してしまいました。
また、このエラーはAを押すと出現します。
インスタンスの設定をよく理解できていない為単純なミスなのかもしれませんがご教授お願いします。
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all UnityEngine.MonoBehaviour:.ctor() Button:.ctor() MakimonoscriptGr:Update() (at Assets/Gallry/MakimonoscriptGr.cs:29)
該当のソースコード
public class MakimonoscriptGr : MonoBehaviour { Button btn; void Start() { //btn = GetComponent<Button>(); btn = GameObject.Find("Canvas/ボタンオブジェクトの名前").GetComponent<Button>(); //btn.interactable = false; } void Update() { if (Input.GetKeyDown(KeyCode.A))//Aを押したら切り替え { // btn.interactable = true; // btn.GetComponent<Button>().interactable = true; btn = new Button(); btn.interactable = true; } } }
試したこと
http://portaltan.hatenablog.com/entry/2016/05/24/144108
こちらのサイトを参考にさせていただきコードを作成しました。
ほかにも Button btn; ⇒ public Button btn;にしてみたりしましたがエラーは起きないのですがオブジェクトを入れることができませんでした。
補足情報(FW/ツールのバージョンなど)
Unity3.4f1

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/04/13 06:45
2019/04/13 07:28
退会済みユーザー
2019/04/14 03:23 編集
2019/04/14 06:27
退会済みユーザー
2019/04/14 12:37