ボス・ステージの作成2(BGMチェンジ)


BGMチェンジ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossTrap : MonoBehaviour
{
public AudioClip closeSound;
public GameObject door_1;
public GameObject boss;
// ★追加(BGMチェンジ)
public AudioClip bossSound;
public AudioSource bgm;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
StartCoroutine(Trap());
}
}
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);
// ★追加(BGMチェンジ)
// ボス専用のBGMスタート
bgm.clip = bossSound;
bgm.Play();
boss.SetActive(true);
}
}


【2022版】DarkCastle(全39回)
他のコースを見る

BGMチェンジ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossTrap : MonoBehaviour
{
public AudioClip closeSound;
public GameObject door_1;
public GameObject boss;
// ★追加(BGMチェンジ)
public AudioClip bossSound;
public AudioSource bgm;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
StartCoroutine(Trap());
}
}
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);
// ★追加(BGMチェンジ)
// ボス専用のBGMスタート
bgm.clip = bossSound;
bgm.Play();
boss.SetActive(true);
}
}


ボス・ステージの作成2(BGMチェンジ)