|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
MJR09 |
extends AudioStreamPlayer2D
var coinSFX = preload(“res://GodotIntro-Assets/Audio/coin.tres”)
func play_coin_sfx ():
stream = coinSFX
play()
This is the code for the coin sound effect in my game. It’s supposed to play when the playable character touches the coin. It’s not showing any error messages, but I still can’t hear any sound when the character touches the coin? The only things that happens for me is that, theres either no sound effects, or it keeps looping. Can you guys please help?
I don’t think a .tres file can be used as a sound?!
Schweini | 2020-05-28 06:08
|
|
|
|
Reply From: |
Okan Ozdemir |
Here is the code for this:
func shooteffect():
var shooteffect = AudioStreamPlayer3D.new()
add_child(shooteffect, true)
var ko : Array = ["res://Voices/BangFireWork/bang/bang_01.wav",
"res://Voices/BangFireWork/bang/bang_02.wav",
"res://Voices/BangFireWork/bang/bang_03.wav",
"res://Voices/BangFireWork/bang/bang_04.wav",
"res://Voices/BangFireWork/bang/bang_05.wav",
"res://Voices/BangFireWork/bang/bang_06.wav",
"res://Voices/BangFireWork/bang/bang_07.wav",
"res://Voices/BangFireWork/bang/bang_08.wav",
"res://Voices/BangFireWork/bang/bang_09.wav",
"res://Voices/BangFireWork/bang/bang_10.wav"]
randomize()
ko.shuffle()
shooteffect.stream = load(str(ko.front()))
# shooteffect.stream
shooteffect.play()
shooteffect.playing = true
shooteffect.unit_db = Global_batch.player_fx_level
# print("Global_batch.player_fx_level", Global_batch.player_fx_level)
yield(get_tree().create_timer(0.5), "timeout")
shooteffect.queue_free()
shooteffect.free()
We assume that you have audiostreamer in tres file as the main root Dear Sir / madam
Yes, Im using the Coin.tres file in the Audio Player.
But my game isn’t a 3D FPS game though.
Pleaase use direct var shooteffect = AudioStreamPlayer2D.new() code, not the tres file format
Okan Ozdemir | 2020-05-28 22:32