実現したいこと
- ビルド後のアプリケーション上でも、Animationの切替が正常に行われる
前提
移動時にAnimationを切り替えるスクリプトを組んでいます
エディタ上ではBlendTreeの値、モーション共に正常に動作するのですが、ビルド後のアプリケーション上だとAnimationが切り替わらず、想定通り動作しません。
何が原因なのでしょうか?
Animatorの概要
WASDキーを押すと移動Animationが再生され、止まると待機Animationが再生される、といったごく普通のもので、BlendTreeで制御しています。
該当のソースコード
cs
1using UnityEngine; 2using UnityEngine.InputSystem; 3 4public class PlayerLocomotion : CharacterLocomotion 5{ 6 [SerializeField] private Animator anim; 7 8 [SerializeField, Label("移動可能か?")] private bool isCanMove = true; 9 [SerializeField, UnEditable] private Vector2 moveVector; 10 [SerializeField, Label("移動スピード")] private int moveSpeed = 5; 11 12 [SerializeField, Label("アクション名 - 移動"), UnEditable] private string actionName_Move = "Move"; 13 [SerializeField, Label("Anim変数名 - 移動Blend")] private string animName_Move; 14 15 private Rigidbody rb; 16 private PlayerInput playerInput; 17 18 private Vector3 latestPos; 19 20 private void Start() 21 { 22 rb = GetComponent<Rigidbody>(); 23 } 24 25 private void FixedUpdate() 26 { 27 Move(); 28 } 29 30 private void OnEnable() 31 { 32 if (TryGetComponent<PlayerInput>(out var component)) 33 { 34 playerInput = component; 35 36 playerInput.actions[actionName_Move].performed += OnMove; 37 playerInput.actions[actionName_Move].canceled += OnMove; 38 else return; 39 } 40 private void OnDisable() 41 { 42 if (TryGetComponent<PlayerInput>(out var component)) 43 { 44 playerInput = component; 45 46 playerInput.actions[actionName_Move].performed -= OnMove; 47 playerInput.actions[actionName_Move].canceled -= OnMove; 48 } 49 else return; 50 } 51 52 private void Move() 53 { 54 //移動処理 55 rb.MovePosition(transform.position + new Vector3(moveVector.x, 0, moveVector.y) * moveSpeed * Time.deltaTime); 56 if (moveVector == Vector2.zero) rb.velocity = Vector3.zero; 57 58 //移動方向に向く 59 var diff = transform.position - latestPos; 60 latestPos = transform.position; 61 if (diff.magnitude > 0.01f) 62 { 63 //leapで少しずつ回転させる(x,z軸は固定) 64 transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(diff), 360 * Time.deltaTime); 65 } 66 67 //移動アニメーション 68 var animMove = anim.GetFloat(animName_Move); 69 var animMove_after = moveVector == Vector2.zero ? animMove - 0.1f : animMove + 0.1f; 70 //blendの値を変更 71 anim.SetFloat(animName_Move, Mathf.Clamp(animMove_after, 0, 1)); 72 } 73 74 private void OnMove(InputAction.CallbackContext context) 75 { 76 if (context.canceled) 77 { 78 moveVector = Vector2.zero; 79 return; 80 } 81 82 if (!isCanMove) return; 83 84 moveVector = context.ReadValue<Vector2>(); 85 } 86 87//~~~~~ 88 89}
試したこと
- Libraryフォルダの削除・再生成
補足情報(FW/ツールのバージョンなど)
Unity 2022.3.0
動いてるものを調べないとなんとも言えません。とりあえずログ出力を仕込んで、ログを調べてビルドしたアプリケーションでどのような挙動になっているか確かめるのが良いと思います。ビルドしたアプリケーションでもデバッグしたりログは出力できます。

回答2件
あなたの回答
tips
プレビュー