実現したいこと
アニメーターを取得したい
発生している問題・分からないこと
普通にアニメーターを取得しようとしたら何故か取得できません。
エラーメッセージ
error
1NullReferenceException: Object reference not set to an instance of an object 2PlayerAnimator.Update () (at Assets/Scripts/PlayerAnimator.cs:16)
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerAnimator : MonoBehaviour { private const string IS_WALKING="IsWalking"; private Animator animator; [SerializeField] private PlayerController player; private void Awake() { if(TryGetComponent<Animator>(out animator)){} } private void Update() { animator.SetBool(IS_WALKING,player.IsWalking()); } }
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
GetComponent にしたりしたり調べたりしたけど出てこなかった。Debug.Log(animator). でnull になるのでそもそも取得が失敗してしまっている
補足
特になし
回答1件
あなたの回答
tips
プレビュー