Wednesday, 5 June 2013

Adding Health to the Character, Respawning and Healthups

Health was added to the Main Character with creating a Health variable that change when it interacted with a script that dealth "damage". Basically, damage is the decreasing of the value assigned to the Health variable, as the health goes lower the GUI image for Health changes. Overall I have 11 images for health, when the Health variable is at 100, the healthbar looks full, when it is at 0 it is empty.
Additionally I managed to set the script that when the player ran out of health the script would send a message that would activate a function within my main player controller script that would cause it to respawn at the character respawn point with all it's health. Effectively, if the player were to run out of health or fall out of the game they would have all their health returned to them and be brought back to the spawn point. To the right is an image of the Health at 50% when the character has taken some damage from an object with the damage script. (Bare in mind this is not the final resolution for the game).

Furthermore I've managed to create a script that would add a value to the health when the character would interact with it. The object itself acts as a type of Health pickup and is destroyed when the main player touches it. Similarly the same method is used with the checkpoint as I have both object rotating in mid-air, they both get destroyed on contact but do different functions.
Below is the code for the Health-up script.
function OnTriggerEnter (other : Collider) {
    other.gameObject.SendMessage ("hup30", SendMessageOptions.DontRequireReceiver);
    Destroy (gameObject);
}

function hup30 ()
{
HEALTH = HEALTH + 30;
}

And below this text is the code for the checkpoint script.

var spawnPoint : Transform;

function OnTriggerEnter (other : Collider) {
 if(other.tag == "Player") {
 spawnPoint.position = Vector3(75, 10, 0);
 Destroy(gameObject);
 }

}

No comments:

Post a Comment