0 votes

extends AudioStreamPlayer2D

var coinSFX = preload("res://GodotIntro-Assets/Audio/coin.tres")

func playcoinsfx ():

stream = coinSFX

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?

in Engine by (12 points)

I don't think a .tres file can be used as a sound?!

1 Answer

0 votes

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", 
    shooteffect.stream = load(str(ko.front()))
#   shooteffect.stream
    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")

We assume that you have audiostreamer in tres file as the main root Dear Sir / madam

by (193 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.