実現したいこと
ゲーム開始とともにヒーローを歩かせて、ある位置まで行くと攻撃アニメーションに切り替える。
発生している問題・エラーメッセージ
タイトルにある通りAnimatorにattackアニメーションを追加するともともとあったwalkアニメーションが正常に動かなくなってしまいます。
現状
まずはヒーローを前進させるスクリプトです。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class HeroManager : MonoBehaviour { 6 7 //グローバル変数 8 public float speed; 9 10 //メンバ変数 11 private Vector2 heroPos; 12 private bool isTouched = false; 13 14 void Update(){ 15 if (!isTouched) { 16 //ヒーローの移動 17 heroPos = this.GetComponent<RectTransform> ().offsetMin; 18 this.GetComponent<RectTransform> ().offsetMin = new Vector2 (heroPos.x + speed, heroPos.y); 19 this.GetComponent<RectTransform> ().sizeDelta = new Vector2 (70, 70); 20 } 21 } 22 23 24 void OnTriggerEnter2D (Collider2D other){ 25 Debug.Log ("collision"); 26 isTouched = true; 27 } 28 29 void OnTriggerExit2D(Collider2D other){ 30 isTouched = false; 31 } 32} 33
次にwalkアニメーションとattackアニメーションです。
そこで
Animatorがこの状態の時にゲームを開始するとしっかり歩いてくれるのですが
このようにattackアニメーションを追加するだけで、その場で歩いてしまいます。
attackアニメーションのAnchored Position.xが原因な気もするのですが...
お願いしたいこと
スクリプトにあるようにisTouchedがtrueになった時にattackアニメーションに切り替わるようにしたいです。
お願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。