Unity Game Flow學(xué)習(xí)筆記
unity學(xué)起來還真的是有點痛苦救崔,跟自己學(xué)習(xí)習(xí)慣有很大關(guān)系戈轿,總是去找想要的功能點,然后希望加以組合决摧,不太會按部就班的跟著教程走,典型自虐型。
游戲框架是最最最重要的部分掌桩,沒有骨架肌肉边锁,皮毛都談不上,如何搭設(shè)框架波岛,瞎摸索中茅坛。
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour
{
bool alive = true;
bool WinCondition = false;
//int level = 0;
void Start()
{
StartCoroutine(gameLoop());
}
IEnumerator gameLoop()
{
yield return StartCoroutine(LevelStart());
yield return StartCoroutine(LevelPlay());
yield return StartCoroutine(LevelEnd());
if (WinCondition)
{
//Application.LoadLevel(++level);
Debug.Log("執(zhí)行下一場景");
}
else
{
StartCoroutine(gameLoop());
Debug.Log("游戲主循環(huán)");
}
}
IEnumerator test()
{
Debug.Log("test");
yield return null;
}
IEnumerator LevelStart()
{
Debug.Log("開始游戲");
alive = true;
yield return new WaitForSeconds(1f);
}
IEnumerator LevelPlay()
{
while (alive)
{
transform.position = new Vector2(Mathf.Sin(Time.time), 0);
Debug.Log("各種戰(zhàn)斗");
if (Input.GetMouseButtonDown(0))
{
alive = false;
}
yield return null;
}
}
IEnumerator LevelEnd()
{
Debug.Log("游戲結(jié)束");
yield return new WaitForSeconds(1f);
}
}
后面慢慢添加