ボス・ステージの作成4(扉が開く)

ステージクリアー
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BossTrap : MonoBehaviour
{
public AudioClip closeSound;
public GameObject door_1;
public GameObject boss;
public AudioClip bossSound;
public AudioSource bgm;
public GameObject bossTitle;
public string titleName;
// ★追加(ステージクリアー)
public AudioClip clearSound;
public AudioClip mainSound;
public GameObject door_2;
private bool isClear = false;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
StartCoroutine(Trap());
}
}
// ★追加(ステージクリアー)
private void Update()
{
if(boss == null && isClear == false)
{
// ここの一連の処理は1回で終了させる(テクニック)
isClear = true;
StartCoroutine(Clear());
}
}
private IEnumerator Trap()
{
AudioSource.PlayClipAtPoint(closeSound, Camera.main.transform.position);
door_1.SetActive(true);
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
yield return new WaitForSeconds(1f);
bossTitle.SetActive(true);
bossTitle.GetComponent<Text>().text = titleName;
bgm.clip = bossSound;
bgm.Play();
boss.SetActive(true);
yield return new WaitForSeconds(3f);
bossTitle.SetActive(false);
}
// ★追加(ステージクリアー)
private IEnumerator Clear()
{
// クリアーサウンド
AudioSource.PlayClipAtPoint(clearSound, Camera.main.transform.position);
// 扉が開く(次に進める)
door_2.SetActive(false);
yield return new WaitForSeconds(1f);
// BGMをメインサウンドに戻す
bgm.clip = mainSound;
bgm.Play();
}
}


【2022版】DarkCastle(全39回)
他のコースを見る
ステージクリアー
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BossTrap : MonoBehaviour
{
public AudioClip closeSound;
public GameObject door_1;
public GameObject boss;
public AudioClip bossSound;
public AudioSource bgm;
public GameObject bossTitle;
public string titleName;
// ★追加(ステージクリアー)
public AudioClip clearSound;
public AudioClip mainSound;
public GameObject door_2;
private bool isClear = false;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
StartCoroutine(Trap());
}
}
// ★追加(ステージクリアー)
private void Update()
{
if(boss == null && isClear == false)
{
// ここの一連の処理は1回で終了させる(テクニック)
isClear = true;
StartCoroutine(Clear());
}
}
private IEnumerator Trap()
{
AudioSource.PlayClipAtPoint(closeSound, Camera.main.transform.position);
door_1.SetActive(true);
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
yield return new WaitForSeconds(1f);
bossTitle.SetActive(true);
bossTitle.GetComponent<Text>().text = titleName;
bgm.clip = bossSound;
bgm.Play();
boss.SetActive(true);
yield return new WaitForSeconds(3f);
bossTitle.SetActive(false);
}
// ★追加(ステージクリアー)
private IEnumerator Clear()
{
// クリアーサウンド
AudioSource.PlayClipAtPoint(clearSound, Camera.main.transform.position);
// 扉が開く(次に進める)
door_2.SetActive(false);
yield return new WaitForSeconds(1f);
// BGMをメインサウンドに戻す
bgm.clip = mainSound;
bgm.Play();
}
}


ボス・ステージの作成4(扉が開く)