効果音を鳴らし終えた後にシーン切り替え
効果音を鳴らし終えた後に,シーンを切り替えたい場合は StartCoroutine を使えば良いっぽい.
コード
- スタートボタンに下記StartActionListener を貼り付ける.
- 効果音がなり,スタートボタンが一瞬大きくなる.
- "GameScene" へ遷移する.
public class StartActionListener : MonoBehaviour { private float timer = 0; private float interval = 0.3f; private float scaleRate = 0.2f; void Update() { if (this.timer > 0) { this.timer -= Time.deltaTime; this.transform.localScale = (this.scaleRate * this.timer / this.interval) * Vector3.one; } } void OnMouseDown() { this.timer = this.interval; this.audio.Play(); StartCoroutine("GoToGameScene"); } IEnumerator GoToGameScene() { yield return new WaitForSeconds(2.0f); Application.LoadLevel(Scenes.gameScene); } }