All that a Strawberry does is:
1.) Play its idle animation
2.) Disappear when collected
Add a script to the Strawberry node
(1.) In the process function play the idle animation.
We will use Signals to detect collisions.
Select the Strawberry node
In the Inspector select the Node tab
Then select the Signals tab
Connect the _on_body_entered() signal
How do we know which body entered the strawberry?
Return to the Player scene.
In the Inspector choose the Node tab
Then select the Groups tab
Click on the + sign to add a new group
Name it Player and make it global
This is a way of tagging nodes so that we can identify them.
Add a function to increase the players score
While we are here lets add a way to increase the number of strawberries collected by the player.
Add a new variable called strawberry_count
Now add a function called inc_strawberry()
increase strawberry count by 1
Return to the Strawberry scene.
(2.) In the Strawberry script
in the _on_body_entered() function
if the body is in the group called Player
Call the players inc_strawberry function
Destroy the strawberry with queue_free()
We can now collect strawberries and keep track of how many we have collected.
Scatter some strawberries throughout the level to collect.