Game Development Reference
In-Depth Information
The ball is going to be a collector, which collects coins or other things (collectables) by
touching them. Therefore, we need now two additional scripts:
Collectable
, which marks
an object as collectable, and
Collector
, which checks for collision with the collectables that
exist in the scene.
Collectable
script is shown in Listing 26.
Listing 26:
Script for collectable objects
As you can see, both
Start()
and
Update()
functions are empty. This means that
Collectable
script is passive, and all what it does is to wait for the collector to call its
Collect()
function.
The collector is also going to use
radius
value to test collision with the collectable. When
Collect()
function is called, the script sends a message called
Collected
and attaches an
object with this message
owner
. In this context, the value of
owner
refers to the collector
that called
Collect()
(i.e. the collector that has just collided the collectable). The attachment