import { _decorator, AudioClip, CCFloat, Component, Node } from 'cc'; import { SoundManager } from '../Manager/SoundManager'; const { ccclass, property } = _decorator; @ccclass('SequenceSound') export class SequenceSound extends Component { @property({ type: CCFloat, visible: true }) private _duration: number = 0.5; @property({ type: AudioClip, visible: true }) private _audioClips: AudioClip[] = []; private _currentIndex = 0; private _timer = 0; protected update(dt: number): void { if (this._timer > 0) { this._timer -= dt; } } public playSound(volume: number = 1) { if (this._timer > 0) { SoundManager.instance.playSfx(this._audioClips[this._currentIndex], { volume }); this._currentIndex++; if (this._currentIndex >= this._audioClips.length) this._currentIndex = 0; } else { this._currentIndex = 0; SoundManager.instance.playSfx(this._audioClips[this._currentIndex], { volume }); } this._timer = this._duration; } }