
import { _decorator, Component, Node, AudioSource,assert,game} from 'cc';
const { ccclass, property } = _decorator;

 
@ccclass('audio')
export class audio extends Component {
   
    @property({type:AudioSource})
     public audio: AudioSource = null!;


     onLoad () {
        // 获取 AudioSource 组件
        const audioSource = this.node.getComponent(AudioSource)!;
        // 检查是否含有 AudioSource，如果没有，则输出错误消息
        assert(audioSource);
        // 将组件赋到全局变量 _audioSource 中
        this.audio= audioSource;
        game.addPersistRootNode(this.node);

        // 将节点封装到管理器中
        //audioManager.instance.init(this.audio);

        this. play ();
    }

    play () {
        // 播放音乐
        //this.audio.play();
        this.audio.playOnAwake=true;
    }

    pause () {
        // 暂停音乐
        this.audio.pause();
    }
    
}

