Eda minigame but new branch
This commit is contained in:
30
Assets/Scripts/PlayAudioOnCamera.cs
Normal file
30
Assets/Scripts/PlayAudioOnCamera.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayAudioOnCamera : MonoBehaviour
|
||||
{
|
||||
public AudioClip clip; // assign your audio file in the Inspector
|
||||
private AudioSource audioSource;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Get or add an AudioSource to this GameObject
|
||||
audioSource = gameObject.GetComponent<AudioSource>();
|
||||
if (audioSource == null)
|
||||
{
|
||||
audioSource = gameObject.AddComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Assign the audio clip
|
||||
if (clip != null)
|
||||
{
|
||||
audioSource.clip = clip;
|
||||
audioSource.playOnAwake = false;
|
||||
audioSource.loop = false; // change to true if you want looping
|
||||
audioSource.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("PlayAudioOnCamera: No audio clip assigned!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user