Launch | Download (v1.5)

Description

The purpose of this example is to create a game using only script written in UnityScript (JavaScript) language. Energy Bar Toolkit is written entirely in C# and it can be easily adapted to use with different languages. What we did here is to use SimpleEvent from Event System and attached it as a component to each land mine and health objects.

There are 3 types of objects on the scene:

Ball Land mine Health

SimpleEvent needs to do these three things:

  • Change energy bar value when ball collides with a land mine or health object.
  • Send message about what has been touched to appropriately react.
  • Send message about current energy value (I want to display the value as health bar).

To do so, I’ve configured SimpleEvent for land mine object:

You should notice that:

  • Trigger is set to react on Tags → Player tag
  • On Trigger Enter is set to decrease the value bar by 10% (0.1)
  • There are two messages sent:
    • OnLandMineTouch(GameObject) to colliding object. This one is to make the ball fly away from the mine. The code looks like this:
function OnLandmineTouch(caller : GameObject) {
    rigidbody.AddExplosionForce(explosionForce, caller.transform.position, explosionRadius);
    GameObject.Destroy(caller);
}
  • OnHealthChange(float) to inform about health value change and react when it falls to zero:
function OnHealthChange(currentValue : float) {
    if (currentValue == 0) {
        Debug.Log("Death cause: health dropped to 0!");
        OnDie(gameObject);
    }
}

What if player will fell of the game plane before killing himself because of mines? Just under the game plane there is something that is called the dead zone. This is a large plane that will kill the player immediately.

Of course death zone is also managed by SimpleEvent:

  • On Tag → Player
  • Set energy bar value to 0
  • Send message to colliding OnDie(GameObject)

And that’s it!