Unity Game Flow学习笔记

作者: 皿卜土 | 来源:发表于2016-07-22 17:11 被阅读0次

Unity Game Flow学习笔记


unity学起来还真的是有点痛苦,跟自己学习习惯有很大关系,总是去找想要的功能点,然后希望加以组合,不太会按部就班的跟着教程走,典型自虐型。
游戏框架是最最最重要的部分,没有骨架肌肉,皮毛都谈不上,如何搭设框架,瞎摸索中。

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("执行下一场景");
        }
        else
        {
            StartCoroutine(gameLoop());
            Debug.Log("游戏主循环");
        }
    }

    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("各种战斗");
            if (Input.GetMouseButtonDown(0))
            {
                alive = false;
            }
            yield return null;
        }
    }
    IEnumerator LevelEnd()
    {
        Debug.Log("游戏结束");
        yield return new WaitForSeconds(1f);
    }

}

后面慢慢添加

相关文章

网友评论

    本文标题:Unity Game Flow学习笔记

    本文链接:https://www.haomeiwen.com/subject/jxmijttx.html