Audio Source Changes
This commit is contained in:
28
Assets/Scripts/AudioPlayer.cs
Normal file
28
Assets/Scripts/AudioPlayer.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MyAudioPlayer : MonoBehaviour
|
||||
{
|
||||
private AudioSource audioSource;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// Try to get it from the current object first
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
|
||||
// Fallback: search the scene (safer than lazy Find at Play)
|
||||
if (audioSource == null)
|
||||
{
|
||||
GameObject go = GameObject.Find("AudioSource");
|
||||
if (go != null)
|
||||
{
|
||||
audioSource = go.GetComponent<AudioSource>();
|
||||
}
|
||||
}
|
||||
|
||||
// Final safety check
|
||||
if (audioSource == null)
|
||||
{
|
||||
Debug.LogError("AudioSource not found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/AudioPlayer.cs.meta
Normal file
2
Assets/Scripts/AudioPlayer.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb32ca4da2d356744a41f21b57392113
|
||||
22
Assets/Scripts/BackgroundMusicManager.cs
Normal file
22
Assets/Scripts/BackgroundMusicManager.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BackgroundMusicManager : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
var backgroundMusicAudioSource = GetComponent<AudioSource>();
|
||||
|
||||
backgroundMusicAudioSource.Play();
|
||||
|
||||
Debug.Log("Audio playing: " + backgroundMusicAudioSource.isPlaying);
|
||||
Debug.Log("Volume: " + backgroundMusicAudioSource.volume);
|
||||
Debug.Log("Clip: " + backgroundMusicAudioSource.clip);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/BackgroundMusicManager.cs.meta
Normal file
2
Assets/Scripts/BackgroundMusicManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf26851e3c5220940afe1e283a9e297a
|
||||
Reference in New Issue
Block a user