0 votes

Here's the code.

extends Node2D


export var value = 1
var coin_get : bool


func _ready():

    print(get_owner())
    print(get_owner().coins_collected)
    get_node("Area2D").connect("body_entered", self, "_collect_coin")


func _collect_coin(body):
    print(body)
    $CoinSound.play()
    if str(body) == "Player:[KinematicBody2D:1294]":
        get_owner().coins_collected += value
        print(get_owner().coins_collected)
    queue_free()

All of the code under the collectcoin function runs except for the coin sound. I've looked online and am pretty sure that that's how you would play sound. If you need anything else I'm happy to give it. Thanks.

Godot version 3.4
in Engine by (12 points)

Do you get an error message or does it just not play? Have you checked that the node is definately called CoinSound and not Coin_Sound or something similar?

Hi. Your question doesn't clearly state what the $CoinSound is and what are the properties it has. I assume it is an audio stream player. Are you sure you have the correct sound assigned to it as a stream?

Sorry for responding so late. No error message it just wont play. And yes the node is definitely called CoinSound

Yes $CoinSound is an audio stream player and I have it set to play in the Master Bus. I am also sure that it is the correct sound since I'm able to play it in the editor.

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.