ボスの攻撃を作るその6(BGMを切り替える)



BGMを切り替える
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossCore : MonoBehaviour
{
public GameObject damageEffectPrefab;
private int hitCount;
private Animator anim;
private BossShotBeam bsb;
// ★追加(BGMの変更)
public AudioClip[] bgms;
public AudioSource audioSource;
private void Start()
{
anim = transform.root.GetComponent<Animator>();
bsb = GetComponent<BossShotBeam>();
Invoke("GoToForm1", 3.0f);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Drone"))
{
hitCount += 1;
Destroy(collision.gameObject);
GameObject effect = Instantiate(damageEffectPrefab, collision.transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
if (hitCount == 2)
{
anim.SetTrigger("Back_Idle");
Invoke("GoToForm2", 3.0f);
}
else if (hitCount == 5)
{
anim.SetTrigger("Back_Idle");
Invoke("GoToForm3", 3.0f);
}
}
}
void GoToForm1()
{
anim.SetTrigger("Form_1");
// ★追加(BGMの変更)
audioSource.clip = bgms[0];
audioSource.Play();
}
void GoToForm2()
{
anim.SetTrigger("Form_2");
bsb.shotInterval = 50;
// ★追加(BGMの変更)
audioSource.clip = bgms[1];
audioSource.Play();
}
void GoToForm3()
{
anim.SetTrigger("Form_3");
bsb.shotInterval = 30;
// ★追加(BGMの変更)
audioSource.clip = bgms[2];
audioSource.Play();
}
}

【2019版】X_Mission(基礎/全51回)
他のコースを見る


BGMを切り替える
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossCore : MonoBehaviour
{
public GameObject damageEffectPrefab;
private int hitCount;
private Animator anim;
private BossShotBeam bsb;
// ★追加(BGMの変更)
public AudioClip[] bgms;
public AudioSource audioSource;
private void Start()
{
anim = transform.root.GetComponent<Animator>();
bsb = GetComponent<BossShotBeam>();
Invoke("GoToForm1", 3.0f);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Drone"))
{
hitCount += 1;
Destroy(collision.gameObject);
GameObject effect = Instantiate(damageEffectPrefab, collision.transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
if (hitCount == 2)
{
anim.SetTrigger("Back_Idle");
Invoke("GoToForm2", 3.0f);
}
else if (hitCount == 5)
{
anim.SetTrigger("Back_Idle");
Invoke("GoToForm3", 3.0f);
}
}
}
void GoToForm1()
{
anim.SetTrigger("Form_1");
// ★追加(BGMの変更)
audioSource.clip = bgms[0];
audioSource.Play();
}
void GoToForm2()
{
anim.SetTrigger("Form_2");
bsb.shotInterval = 50;
// ★追加(BGMの変更)
audioSource.clip = bgms[1];
audioSource.Play();
}
void GoToForm3()
{
anim.SetTrigger("Form_3");
bsb.shotInterval = 30;
// ★追加(BGMの変更)
audioSource.clip = bgms[2];
audioSource.Play();
}
}

ボスの攻撃を作るその6(BGMを切り替える)