我是Unity中的新成員,正在製作我的第一款2D遊戲。我在這個問題上看到了這個論壇上的幾個主題,但我沒有找到解決方案。Unity2d遊戲拍攝和動畫同步問題
所以我有一個可愛的射擊動畫和子彈代。我的問題是,我必須在動畫中間的某個位置生成子彈,但是角色同時射擊子彈和動畫,這會消耗用戶體驗:)
我附加了一張關於該問題的圖像,現在是子彈初始化的時刻,但正如你所看到的,它已經開始了。
請找我的代碼: 的遊戲管理器更新方法調用attackEnemy功能:
public void Awake(){
animator = GetComponent();
animator.SetTrigger ("enemyIdle");
}
//if the enemy pass this point, they stop shooting, and just go off the scren
private float shootingStopLimit = -6f;
public override void attackPlayer(){
//animator.SetTrigger ("enemyIdle");
if (!isAttacking && gameObject.transform.position.y > shootingStopLimit) {
isAttacking = true;
animator.SetTrigger("enemyShoot");
StartCoroutine(doWait());
gameObject.GetComponentInChildren().fireBullet();
StartCoroutine (Reload());
}
}
private IEnumerator doWait(){
yield return new WaitForSeconds(5);
}
private IEnumerator Reload(){
animator.SetTrigger ("enemyIdle");
int reloadTime = Random.Range (4,7);
yield return new WaitForSeconds(reloadTime);
isAttacking = false;
}......
我的問題: - 我如何可以同步動畫和子彈一代?
爲什麼不doWait()的作品? :)
可以從GameManager更新調用attackPlayer方法嗎?
當屏幕右側到達屏幕的最右側時,敵人會從屏幕右側飛到屏幕左側,使用戶可以看到敵人。我不知道爲什麼,但是他們先給一個拍攝動畫(沒有子彈發生),只有在他們做了閒置之後。任何想法爲什麼?
感謝, ķ
thx隊友,工作就像地獄! – Karoly