Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Rayu |
When my Scene hit it’s time to 0 (Game Over) the ConvasLayer pops up (it becomes visible)
on that CanvasLayer is the Score and Highscore.
and when the time hits 0 and the CanvasLayer pops up i want to add a soundeffect
Game Scene Script:
func _ready() -> void:
$ControlScore/ScoreCount.text = str(Globals.Score)
set_process(true)
var actor_id = randi() % 4 + 1
if actor_id == 1:
spawn_player1(1)
for _i in range(4 + Globals.Score):
spawn_enemy1()
elif actor_id == 2:
spawn_player2(1)
for _i in range(4 + Globals.Score):
spawn_enemy2()
elif actor_id == 3:
spawn_player3(1)
for _i in range(4 + Globals.Score):
spawn_enemy3()
else:
spawn_player4(1)
for _i in range(4 + Globals.Score):
spawn_enemy4()
# 1 of the player and enemy scripts, all are basically the same
func spawn_player1(num):
for _i in range(num):
var w = Player1.instance()
w.connect("player1_pressed", self, "_on_player1_pressed")
player_container1.add_child(w)
func _on_player1_pressed():
if Globals.timeLeft > 0:
Globals.timeLeft += 5
if Globals.timeLeft > Globals.maxTime:
Globals.timeLeft = Globals.maxTime
Globals.Score += 1
get_tree().call_group("Players", "next_level")
get_tree().call_group("Enemies", "hide_for_time", 0.5)
yield(get_tree().create_timer(0.5), "timeout")
get_tree().change_scene("res://Game.tscn")
func spawn_enemy1():
var rand = floor(rand_range(0, Enemy1.size()))
var piece = Enemy1[rand].instance()
add_child(piece)
ControlTimer Script: (Where the time hits 0 and sends signals )
func _process(delta):
if Globals.timeLeft > 0:
Globals.timeLeft -= delta
$TimerCount.text = str(Globals.timeLeft)
$TimerCount.text = "%d" % Globals.timeLeft
else:
Globals.timeLeft = 0
get_tree().call_group("Player", "game_over")
get_tree().call_group("Enemies", "game_over")
get_tree().call_group("GameOverGroup", "game_over") <---- Game Over Signal to CanvasLayer
CanvasLayer (inherited Scene of Game Scene)
Script of a child node
extends Control
func game_over():
visible = true <---- here the canvas Layer gets Visible and at that point i want to add the Game Over sfx
if Globals.Score > Globals.highscore:
Globals.highscore = Globals.Score
save_highscore()
$VBoxContainer/Best.text = "Best " + str(Globals.highscore)
$VBoxContainer/Score.text = "Score " + str(Globals.Score)
But the signal i coming from a _process delta function it either giving a bug sound or i doesn’t play at all. I’ve tried to put the Sound effect on all functions where the Game Over is happening but it doesn’t play at all.
I don’t know where to put it
oh and btw the Sound effect is on a Autoload