1. 程式人生 > >2D獵寶行動(類掃雷小遊戲)DAY11(完結)

2D獵寶行動(類掃雷小遊戲)DAY11(完結)

1.設計過關與失敗面板

新增過關和失敗的面板

2.處理過關的細節

製作過關特效

3.設計返回按鈕和音效管理器

建立AudioManager類

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

public class AudioManager : MonoBehaviour {

    public static AudioManager _instance;

    public bool isMute = false;

    public AudioClip button;
    public AudioClip dig;
    public AudioClip end;
    public AudioClip hoe;
    public AudioClip hurt;
    public AudioClip die;
    public AudioClip move;
    public AudioClip door;
    public AudioClip pass;
    public AudioClip enemy;
    public AudioClip tnt;
    public AudioClip map;
    public AudioClip pick;
    public AudioClip flag;
    public AudioClip why;
    public AudioClip winbg;

    public AudioSource audioSource;

    private void Awake()
    {
        _instance = this;
        DontDestroyOnLoad(gameObject);
    }
}

4.使用音效管理器播放聲音

完善方法

  public void SwitchMuteState()
    {
        isMute = !isMute;
        if (isMute)
        {
            StopBGM();
        }
        else
        {
            PlayBGM();
        }
        DataManager._instance.SetMuteState(isMute);
    }

    public void PlayClip(AudioClip clip)
    {
        if(isMute == false)
        {
            AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
        }
    }

    public void PlayBGM()
    {
        if(isMute == false)
        {
            audioSource.Play();
        }
    }

    public void StopBGM()
    {
        audioSource.Stop();
    }

5.釋出遊戲