add the connection with the editor and can test the json now
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class OpAudioPlayer : MonoBehaviour
|
||||
{
|
||||
public AudioSource audioSource;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (audioSource == null)
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
|
||||
if (audioSource == null)
|
||||
{
|
||||
Debug.LogError("OpAudioPlayer: 找不到 AudioSource 组件。请确保组件已添加或在 Inspector 中设置。");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
audioSource.loop = true;
|
||||
|
||||
if (!audioSource.isPlaying)
|
||||
{
|
||||
audioSource.Play();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (audioSource != null && audioSource.isPlaying)
|
||||
{
|
||||
audioSource.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user