Unityでスクリプトでスプライトを切り替えたいと考えております。
publicでセットしたスプライトを切り替えたいのですが、
Debug.Log (string.Format("a{0:D}", this.walkDown.Length));
を呼ぶとフレームごとに返ってくる値が変わってきます。
2回に1回、こちらの値が0になってしまい、想定している挙動と
違う動きになってしまうのですが、実装が間違えているのでしょうか。
Unity
1using UnityEngine; 2using System.Collections; 3 4public class PlayerAnimation : MonoBehaviour { 5 6 public Sprite[] walkDown; 7 SpriteRenderer sp; 8 float animeTime = 0.0f; 9 const float animeTimeMax = 1.0f; 10 int animeCount = 0; 11 12 // Use this for initialization 13 void Start () { 14 this.sp = GetComponent<SpriteRenderer> (); 15 //this.sp.sprite = this.walkDown [0]; 16 } 17 18 // Update is called once per frame 19 void Update () { 20 this.animeTime += Time.deltaTime; 21 if (this.animeTime >= animeTimeMax) { 22 23 this.animeTime = 0.0f; 24 this.animeCount++; 25 if (this.animeCount >= this.walkDown.Length) { 26 this.animeCount = 0; 27 } 28 //this.sp.sprite = this.walkDown [this.animeCount]; 29 //Debug.Log (this.animeCount); 30 } 31 32 Debug.Log (string.Format("a{0:D}", this.walkDown.Length)); 33 } 34} 35
回答1件
あなたの回答
tips
プレビュー