Unity Primary Case - Angry Birds: 7:20 Add mouse registration event

 First, the purpose

1. Wonder: Angry Birds: How to Make

2. Make study notes so that you can check them next time

2. Reference

1. SIKI Academy

Login - SiKi Academy - Life is endless, learning is endless!

good: URL to learn

3. Attention

1. Version

  1. Unity2017.2.0f3
  2. VS2019
  3. UnityHUB 2.5.6

Action: 1:20 Add mouse registration event

1. Add button component to the button of win interface

 

1. Code GameManager: add replay logic

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;//【20添加鼠标注册事件:添加】

/// <summary>
/// 【Author:xzy;Time:2021-12-29】【10游戏逻辑的判定,实现多只小鸟的飞出:添加】
/// Function:小猪身上的代码
/// </summary>
public class GameManager : MonoBehaviour
{
    /// <summary>List:所有的小鸟【10游戏逻辑的判定,实现多只小鸟的飞出:添加】</summary>
    public List<Bird> birds;

    /// <summary>List:所有的猪【10游戏逻辑的判定,实现多只小鸟的飞出:添加】</summary>
    public List<Pig> pigs;

    /// <summary>单例【10游戏逻辑的判定,实现多只小鸟的飞出:添加】</summary>
    public static GameManager _instance;

    /// <summary>Vector3:初始化位置【11解决重复划线和小鸟轮换速度突然变大的问题:添加】</summary>
    private Vector3 originPos;

    /// <summary>GameObject:赢界面【14 - 添加失败,胜利的游戏UI界面:添加】</summary>
    public GameObject win;

    /// <summary>GameObject:输界面【14 - 添加失败,胜利的游戏UI界面:添加】</summary>
    public GameObject lose;

    /// <summary>GameObject:星星UI【18让星星一颗一颗的显示:添加】</summary>
    public GameObject[] stars;

    private void Awake()
    {
        _instance = this;//单例

        if (birds.Count>0)
        {
            originPos = birds[0].transform.position;//【11解决重复划线和小鸟轮换速度突然变大的问题:添加】
        }
    }

    void Start()
    {
        Initialized();//【10游戏逻辑的判定,实现多只小鸟的飞出:添加】
    }

    /// <summary>
    ///【Author:xzy;Time:2021-12-29】【10游戏逻辑的判定,实现多只小鸟的飞出:添加】
    /// Function: 小猪碰撞检测
    /// </summary>
    private void Initialized()
    {
        for (int i = 0; i < birds.Count; i++)
        {
            //初始化时候,让第一个小鸟能够被弹,其余的都不能
            if (i == 0)
            {
                birds[i].transform.position = originPos;     //第一只小鸟位置在初始化位置【11解决重复划线和小鸟轮换速度突然变大的问题:添加】
                birds[i].enabled = true;
                birds[i].sp.enabled = true;
            }
            else
            {
                birds[i].enabled = false;
                birds[i].sp.enabled = false;
            }
        }
    }

    /// <summary>
    ///【Author:xzy;Time:2021-12-29】【10游戏逻辑的判定,实现多只小鸟的飞出:添加】
    /// Function: 下一只小鸟
    /// </summary>
    public void NextBird()
    {
        if (pigs.Count > 0)
        {
            if (birds.Count > 0)
            {
                //下一只飞吧
                Initialized();
            }
            else
            {
                //输了
                lose.SetActive(true);//【14 - 添加失败,胜利的游戏UI界面:添加】
            }
        }
        else
        {
            //赢了
            win.SetActive(true);//【14 - 添加失败,胜利的游戏UI界面:添加】
        }
    }

    /// <summary>
    ///【Author:xzy;Time:2022-01-01】【14 - 添加失败,胜利的游戏UI界面:添加】
    /// Function: 显示星星
    /// </summary>
    public void ShowStart()
    {
        StartCoroutine("Show"); //开启协程【18让星星一颗一颗的显示:添加】
    }

    /// <summary>
    ///【Author:xzy;Time:2022-01-01】【18让星星一颗一颗的显示:添加】
    /// Function: 星星一颗颗显示
    /// </summary>
    IEnumerator Show()
    {
        //【18让星星一颗一颗的显示:添加】
        for (int i = 0; i < birds.Count + 1; i++)
        {
            yield  return new WaitForSeconds(0.2f);
            stars[i].SetActive(true);
        }
    }

    /// <summary>
    ///【Author:xzy;Time:2022-01-03】【20添加鼠标注册事件:添加】
    /// Function: 重新玩
    /// </summary>
    public void Replay()
    {
        SceneManager.LoadScene(2);
    }

    /// <summary>
    ///【Author:xzy;Time:2022-01-03】【20添加鼠标注册事件:添加】
    /// Function: 回到主界面
    /// </summary>
    public void Home()
    {
        SceneManager.LoadScene(1);
    }

}

 

1. Button add click event

win interface button add event

 

lose interface button add event 

 

1. Scene serial number setting

 

 1. Make a new UI layer for the number of extra points: avoid the score being blocked by other things

 

 1. Code: PausePanel

In order to make the animation pause after the animation finishes playing

 

 

Guess you like

Origin blog.csdn.net/qq_40544338/article/details/122285862