The thrid version of the superdog program had completed.
This version had increased several new item. One is add some items that
make player gain attributes, such as power, hp, and super mode.
These items are similar as the original super mario game.
I used the same sprite to include these items, and each item has different
property. The player has some different states to correspond to the player's
behavior when the player eat these items.
So Second, the player has three states "small dog", "big white dog",
and "big yellow dog". Each state has its game object and animator controller
by itself. And one player object has only one box collision component and
rigidbody. When we change the different state, we would change the size
of box collision dynamically, or our collision detection will get the
wrong determination.
Third, the "big yellow dog" state could shoot the bullets to defeat enemies,
but some enemies aren't affected. We add two kinds of enemies,
one is hedgehog, and another is iron turtle.
We couldn't defeat the iron turtle by shooting the bullets.
The program is a little complicated, but we can learn some import concepts
in developing Unity program.
One is settings the collision detection between different layers,
when we hope some objects have no collision with some objects,
such as the power mushroom has no collision with the enemies and other items.
We could cancel the check in the project settings.
Another is keeping multiple states in one game object.
Because we want the player has different image in different states.
And the player has three main states when eatting the items or touch the
enemies. It has many images and states to maintain, we don't want to
use the same animator controller to control the animation,
so I add three game objects in the player object, and the sub-objects has
one animator. That we could be easier to conrol it.
The player has only one active object at the same time, and the others
are not active.
Thrid, the items are divided two character, one is static and is trigger,
another is dynamic and is not trigger. The mushrooms and stars are the latter,
and the coins and fire-flower are the former.
Because we don't want the former is not affected by the gravity,
so we set the body type is kinematic, and the latter is dynamic.
Because of this, we have two collision method in the same class.
By the way, the object of item has used the sprite renderer to change the
image. When the item is trigger, then it would call the OnTriggerXXX method
when it occurs collision. When it is not trigger, then it would call the
OnCollisionXXX method.
Forth, we use the object-oriented design in the program, it is the basic
concept in program design. The enemies and some bricks have similiar
behavioies, so we use the parent class to define the common behavioies.
And define some virtual method to request the child class to impliment them.
These concepts I think are import to learn the program desing by Unity.
Although I have a long way to go, but I learn much in this implements.
Thanks the online friend to provide the sample program, it is help me much.