タイトルの通りですが、
下記のコードはUpdateでローディングする画像(arrow)を回転アニメーションさせて、
100フレームに達したら初期化処理(initAsync)が走るというものです。
ところが、100フレーム目に達するとarrow画像は固まってしまいます。
StartCoroutineを使って非同期でinitAsyncを走らせているつもりなのですが、どうもうまく行っていないようです。
画像を止めることなく回転させながら、initAsyncを走らせることはできますか?
C#
1▼TestScript 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.EventSystems; 6using System; 7 8public class TestScript : MonoBehaviour { 9 GameObject mArrow; 10 int mUpdateCount; 11 public delegate void Callback(); 12 13 void Start () { 14 mArrow = GameObject.Find("arrow"); 15 } 16 17 void Update () { 18 mUpdateCount++; 19 rotateArrow(); 20 if (mUpdateCount == 100) { 21 StartCoroutine(initAsync(()=>{ 22 Debug.Log("init完了"); 23 })); 24 } 25 } 26 private void rotateArrow() { 27 Vector3 v3 = new Vector3(0, 0, 1f); 28 mArrow.transform.Rotate(v3); 29 } 30 public IEnumerator initAsync(Callback callback) { 31 for (int i = 0; i < 10000; i++) { 32 Debug.Log(i); 33 } 34 yield return new WaitForSeconds(1f); 35 callback(); 36 } 37} 38
◆環境
Unity2017 3.1f1
Windowx 10
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/04 13:51
2019/02/04 14:08
2019/02/04 14:23
2019/02/04 14:37
2019/02/04 14:48