途中でBGMと背景を切り替える
BGMと背景の切り替え
using UnityEngine;
using System.Collections;
public class BGMChange : MonoBehaviour {
private AudioSource audiosource;
public AudioClip bossSound;
void Start () {
audiosource = GameObject.Find("Main Camera").GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other){
if(other.CompareTag("BossCoin")){
// ★BGMを切り替える
audiosource.clip = bossSound;
audiosource.Play();
// ★背景を切り替える
Skybox skybox = GameObject.Find("Main Camera").GetComponent<Skybox>();
skybox.enabled = true;
}
}
}
Unity Code Memo
他のコースを見るBGMと背景の切り替え
using UnityEngine;
using System.Collections;
public class BGMChange : MonoBehaviour {
private AudioSource audiosource;
public AudioClip bossSound;
void Start () {
audiosource = GameObject.Find("Main Camera").GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other){
if(other.CompareTag("BossCoin")){
// ★BGMを切り替える
audiosource.clip = bossSound;
audiosource.Play();
// ★背景を切り替える
Skybox skybox = GameObject.Find("Main Camera").GetComponent<Skybox>();
skybox.enabled = true;
}
}
}
途中でBGMと背景を切り替える