Topic was automatically imported from the old Question2Answer platform.
Asked By
Rob1980
Hi everyone! I desperately need your help. I have three scenes: a player, a coin, and a Main, which contains both. My problem is to add a label that scores the points when the player collects the coin. I tried in every way, looking also in this section, but there is nothing to do! I just can’t start the score! Anybody could help me, please?
could you share us the code?
p7f | 2018-12-03 18:33
What code? Currently, the only code I’ve added is the one of the answer below.
Assuming you have a scene looking something like this?
Main
– Label
– Player
– Coin
— Area2D
you could do a score like so
var score = 0 #hold the score
func addScore(val): # function to add the score
score += val # add val to score
$Label.set_text(score) # Set the text of label to score
func _on_Area2D_area_entered(): # when something enters area2D
addScore(1) # add 1 to score
It doesn’t work! :_(
My scene is something like this:
Main
– Player
– Coin (Area2D)
– CanvasLayer
— Score
I tried to insert the function in the Score script, and addScore () first in the coin script, then in the Main script, but nothing happens. In which scripts should I enter the code?