• 大小: 36.84MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-08
  • 语言: 其他
  • 标签: unity2017  

资源简介

愤怒的小鸟, 源码,里面涉及了unity许多的组件内容,可以很好的学习,初级unity可以学习,

资源截图

代码片段和文件信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour {

    public List birds;
    public List pig;
    public static GameManager _instance; // 单例
    private Vector3 originPos;           // 记录第一只小鸟的位置,第一只小鸟飞出的时候,第二只小鸟接着上第一只小鸟的位置


    public Gameobject win;  // 赢得界面
    public Gameobject lose;

    public Gameobject[] stars;  // 展示星星的数组
    private int starsNum = 0;   // 这局得到星星的个数
    private int totalNum = 10;   // 总关卡数量,用于记录总的星星个数
    
    private void Awake()
    {
        _instance = this;
        if( birds.Count > 0){
            originPos = birds[0].transform.position;

        }
    }

    private void Start()
    {
        Init();
    }
    //ss
    /// 
    /// 初始化小鸟
    /// 

    private void Init()
    {
        for (int i = 0; i < birds.Count; i++) {
            if (i == 0)
            { // 第一只小鸟
                birds[i].transform.position = originPos;
                birds[i].enabled = true;
                birds[i].sp.enabled = true;
                birds[i].canMove = true;
            }
            else {
                birds[i].enabled = false;
                birds[i].sp.enabled = false;
                birds[i].canMove = false;
            }
        }
    }

    /// 
    /// 判定游戏逻辑
    /// 

    public void NextBird()
    {
        if (pig.Count > 0)
        {
            if (birds.Count > 0)
            { 
                // 下一只飞
                Init();
            }
            else {
                // 输了
                lose.SetActive(true);
            }
        }
        else {
            // 赢了
            win.SetActive(true);
        }
    }

    public void ShowStarts()
    {
        StartCoroutine(“show“);
    }

    IEnumerator show()
    {
        for (; starsNum < birds.Count + 1; starsNum++)
        {
            if (starsNum >= stars.Length) {
                break;
            }
            yield return new WaitForSeconds(0.2f);
            stars[starsNum].SetActive(true);
        }
    }

    /// 
    /// 重新开始玩
    /// 

    public void Replay()
    {
        SaveData();
        SceneManager.LoadScene(2);
    }

    /// 
    /// 返回首页
    /// 

    public void Home() {
        SaveData();
        SceneManager.LoadScene(1);
    }

    public void SaveData() {
        // 只存储每关的最大值
        if (starsNum > PlayerPrefs.GetInt(PlayerPrefs.GetString(“nowLevel“))) {
            PlayerPrefs.SetInt(PlayerPrefs.GetString(“nowLevel“) starsNum);
        }

        int sum = 0;
        for (int i = 1; i < totalNum; i++) {
            sum += PlayerPrefs.GetInt(“level“ + i.ToString());
        }
        PlayerPrefs.SetInt(“totalNum“sum); // 存储总星星个数
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-23 19:18  AngryBird\
     目录           0  2018-04-09 14:31  AngryBird\.git\
     文件          40  2018-04-09 14:31  AngryBird\.git\COMMIT_EDITMSG
     文件          23  2018-04-09 14:31  AngryBird\.git\HEAD
     文件         770  2018-04-09 14:31  AngryBird\.git\config
     文件          73  2018-04-09 14:31  AngryBird\.git\description
     目录           0  2018-04-09 14:31  AngryBird\.git\hooks\
     文件         478  2018-04-09 14:31  AngryBird\.git\hooks\applypatch-msg.sample
     文件         896  2018-04-09 14:31  AngryBird\.git\hooks\commit-msg.sample
     文件         189  2018-04-09 14:31  AngryBird\.git\hooks\post-update.sample
     文件         424  2018-04-09 14:31  AngryBird\.git\hooks\pre-applypatch.sample
     文件        1642  2018-04-09 14:31  AngryBird\.git\hooks\pre-commit.sample
     文件        1348  2018-04-09 14:31  AngryBird\.git\hooks\pre-push.sample
     文件        4951  2018-04-09 14:31  AngryBird\.git\hooks\pre-rebase.sample
     文件         544  2018-04-09 14:31  AngryBird\.git\hooks\pre-receive.sample
     文件        1239  2018-04-09 14:31  AngryBird\.git\hooks\prepare-commit-msg.sample
     文件        3610  2018-04-09 14:31  AngryBird\.git\hooks\update.sample
     文件         225  2018-04-09 14:31  AngryBird\.git\index
     目录           0  2018-04-09 14:31  AngryBird\.git\info\
     文件         240  2018-04-09 14:31  AngryBird\.git\info\exclude
     目录           0  2018-04-09 14:31  AngryBird\.git\logs\
     文件         193  2018-04-09 14:31  AngryBird\.git\logs\HEAD
     目录           0  2018-04-09 14:31  AngryBird\.git\logs\refs\
     目录           0  2018-04-09 14:31  AngryBird\.git\logs\refs\heads\
     文件         193  2018-04-09 14:31  AngryBird\.git\logs\refs\heads\master
     目录           0  2018-04-09 14:31  AngryBird\.git\objects\
     目录           0  2018-04-09 14:31  AngryBird\.git\objects\1f\
     文件         751  2018-04-09 14:31  AngryBird\.git\objects\1f\f0c423042b46cb1d617b81efb715defbe8054d
     目录           0  2018-04-09 14:31  AngryBird\.git\objects\3c\
     文件        2112  2018-04-09 14:31  AngryBird\.git\objects\3c\4efe206bd0e7230ad0ae8396a3c883c8207906
     目录           0  2018-04-09 14:31  AngryBird\.git\objects\91\
............此处省略1784个文件信息

评论

共有 条评论