Может быть легче переместить их в объект, затем вы можете вызвать их, используя строку:
const audioBanshees = {
audioBanshee0: this.sound.add('audioBanshee0',{volume: 0.5}),
audioBanshee1: this.sound.add('audioBanshee1',{volume: 0.5}),
audioBanshee2: this.sound.add('audioBanshee2',{volume: 0.5}),
audioBanshee3: this.sound.add('audioBanshee3',{volume: 0.5}),
audioBanshee4: this.sound.add('audioBanshee4',{volume: 0.5})
}
let ref = Math.floor(Math.random() * Math.floor(5));
const audioBansheeScreech = audioBanshees["audioBanshee" + ref];
audioBansheeScreech.play()
Хотя IMO, массив здесь будет более логичным и легче для чтения:
const audioBanshees = [
this.sound.add('audioBanshee0',{volume: 0.5}),
this.sound.add('audioBanshee1',{volume: 0.5}),
this.sound.add('audioBanshee2',{volume: 0.5}),
this.sound.add('audioBanshee3',{volume: 0.5}),
this.sound.add('audioBanshee4',{volume: 0.5})
]
let ref = Math.floor(Math.random() * Math.floor(5));
const audioBansheeScreech = audioBanshees[ref];
audioBansheeScreech.play()