###前提・実現したいこと
初めて質問させていただきます。
ボタンをプレハブ、インスタンス化して使用したいのです。
###発生している問題・エラーメッセージ
エラーメッセージ UnassignedReferenceException: The variable anim of AnimationControler has not been assigned. You probably need to assign the anim variable of the AnimationControler script in the inspector. UnityEngine.Animator.SetInteger (System.String name, Int32 value) (at C:/buildslave/unity/build/artifacts/generated/common/modules/Animation/AnimatorBindings.gen.cs:282) AnimationControler.OnClick1 () (at Assets/AnimationControler.cs:39) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:153) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:634) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:769) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()
###該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimationControler : MonoBehaviour { int a; int v; int b; private Animator anim; public GameObject hoge; // Use this for initialization void Start() { // anim = GetComponent<Animator>(); //a = 10; anim.SetInteger("kuma", a); } // Update is called once per frame // Update is called once per frame public void OnClick1() { a = 1; anim.SetInteger("kuma", a); v = anim.GetInteger("kuma"); //"kuma"変数の現在の値を取得する(Int) } public void OnClick2() { a = 2; anim.SetInteger("kuma", a); v = anim.GetInteger("kuma"); //"kuma"変数の現在の値を取得する(Int) } public void OnClick3() { a = 0; anim.SetInteger("kuma", a); v = anim.GetInteger("kuma"); //"kuma"変数の現在の値を取得する(Int) } }
###試したこと
インスタンス化(プレハブ化)する前は正常に動いたんですが、
プレハブ化後、インスタンスを配置し、
スクリプトをアタッチしたゲームオブジェクト(プレハブ)をアタッチ。on clickの設定をする。
実行し、 OnClick1等のボタンを押すとエラーが出てしまいます。(プレハブ化前と同じ設定)
エラーメッセージはanim(animator)が与えられてない?みたいな意味のようなのですが、
プレハブ化後はその前とは違う処理をしなければならないのでしょうか?
超初心者で申し訳ありません。
調べたつもりなのですがわかりませんでした。
よろしくお願いします。
###補足情報(言語/FW/ツール等のバージョンなど)
unity5.5
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。