Game Development Reference
In-Depth Information
SizeChanger in Listing 31 script begins with looking for a Collector attached to the same
game object. If the collector exists, it is stored in col variable. There are two major functions
in SizeChanger : IncreaseSize() and DecreaseSize() . IncreaseSize() is called by Food script,
when the collector hits a collectable that has the script Food attached to it. IncreaseSize()
begins with checking the value of currentSize variable; if the value is not zero, the
function returns false , which means no food can be taken right now. However, if currentS-
ize is zero, the value of amount parameter is stored in currentSize , and the scale of the ball
(collector) is increased with the same value. In line 28, we use Invoke() function to setup
the execution of another function later on. In this case, we specify DecreaseSize() function
by writing its name, and we set the delay to the value of duration parameter. Finally, if col
variable is not null (i.e. Collector script is attached to the game object), we multiply its ra-
dius by the value of currentSize , so the radius becomes suitable for the new size of the ball.
Search WWH ::




Custom Search