ボス戦専用のフィールドを作り込むその2
3Dの音響効果の発生
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;
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");
audioSource.clip = bgms[0];
audioSource.Play();
// ★追加(3Dの音響効果)
audioSource.spatialBlend = 1;
}
void GoToForm2()
{
anim.SetTrigger("Form_2");
bsb.shotInterval = 50;
audioSource.clip = bgms[1];
audioSource.Play();
}
void GoToForm3()
{
anim.SetTrigger("Form_3");
bsb.shotInterval = 30;
audioSource.clip = bgms[2];
audioSource.Play();
}
}
【2019版】X_Mission(基礎/全51回)
他のコースを見る3Dの音響効果の発生
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;
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");
audioSource.clip = bgms[0];
audioSource.Play();
// ★追加(3Dの音響効果)
audioSource.spatialBlend = 1;
}
void GoToForm2()
{
anim.SetTrigger("Form_2");
bsb.shotInterval = 50;
audioSource.clip = bgms[1];
audioSource.Play();
}
void GoToForm3()
{
anim.SetTrigger("Form_3");
bsb.shotInterval = 30;
audioSource.clip = bgms[2];
audioSource.Play();
}
}
ボス戦専用のフィールドを作り込むその2