![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Idleman |
Hello, I have a little problem here. The idea is that to have an area2d to detect player enter, then play a sound. So If I instance the area2d scene as a child of any node, the node will plays a sound once player enters.
The sounds are preload in a global AudioManager script, I first get the editor_description of the parent node. Then match the description to the sound in a list, then play the match name of the sound from the AudioManager. Things are fine until the last step that I can not seem to inject the variable of the name of the sound to the play function. It gives me a expected identifier as member error. Is that a correct way to input the name of sound into the script? Thank you.
extends Area2D
var soundName = ""
func _ready():
soundName = get_parent().editor_description
func play_sound(inputName):
AudioManager.play_sound(AudioManager.entitySounds.(inputName), 0)
func _on_SoundTrigger_body_entered(body):
if body.name == "Player":
play_sound(soundName)