ゲームAI備忘録

ゲームAIに使えそうな知識を備忘録として書き留める

人助けと思って何卒インストールをば! 詰碁/ アルコネ/ 五目並べ

効果音を鳴らし終えた後にシーン切り替え

効果音を鳴らし終えた後に,シーンを切り替えたい場合は 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);
	}
}