using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SoundController : MonoBehaviour { AudioSource audio; [SerializeField] int currentScreenIndex; //現在のシーンID ////BGM音源 0=タイトルシーン 1=メニューシーン 2=ゲームシーン [SerializeField] AudioClip[] bgm; // Use this for initialization void Start () { audio = GetComponent(); currentScreenIndex = SceneManager.GetActiveScene().buildIndex; audio.clip = bgm[currentScreenIndex]; audio.Play(); } public void AudioPlay(string audioName) { GameObject obj; try { obj = GameObject.Find(audioName); } catch//オブジェクトを発見できなかった場合、プレハブからロード { obj = (GameObject)Resources.Load(audioName); } //obj = (GameObject)Resources.Load(audioName); audio = obj.GetComponent(); audio.Play(); } }