Launch! | Download (v1.5.1)

Description

The purpose of this example is to show how the Event System can be used. It’s very similar to Minefield Example, so I recommend to check out the other demo, and here I will write about differences.

Know How

Hearts Health Bar

I’ve used heart progress bar (Energy Bar Repeat Renderer) to indicate player health.

Effect is set to Cut with direction BottomToTop. I wanted the step to be 1/2 (half heart).

And to make this effect work I’ve changed Value Max to 10. 10 steps for 5 hearts.

Time Energy Bar

On top-right screen corner you can see a simple timer. It’s also energy bar with the Radial fill direction. It’s built on three textures:

Bg Bar Fg

Of course the second one could be white so you can set its color in the inspector.

In order to make this bar animation more smooth, I’ve changed Energy Bar Max Value to 1000.

I’ve killed him!

You may notice that when you’re killed by red cube, he will be jumping in triumph of defeating you. When using the Event System it may be little tricky to find out who has killed the player. You must know that in Simple Events messages are sent in declaration order. With that knowledge…

…I’ve declared two messages:

  • First to OnEnemyCube(caller : GameObject) to collider. This one makes player jump away from the enemy and saves this enemy instance in lastEnemy field:
function OnEnemyCube(enemy : GameObject) {
    if (!alive) { return; }
    lastEnemy = enemy;
    rigidbody.AddExplosionForce(enemyForce, enemy.transform.position, 5);
}
  • Second to OnHealthChange(value : float) to collider. This one makes player to disappear on death and enemy to jump with happiness.
function OnHealthChange(val : float) {
    if (!alive) { return; }

    if (val <= 0) {
        renderer.enabled = false;
        alive = false;
        
        if (lastEnemy != null) {
            var enemy = lastEnemy.GetComponent(CA_Enemy);
            enemy.MakeHappy();
        }
    }
}