Hi, I am a student who wants to create a 'RPG' style 1 level game for my Final Major Project at college. We have no teachers in the college with knowledge of Unity and its the first time using it myself, I have managed to teach myself how to attach animation to keys (for walking etc) and create a controllable 3rd person character.
However I would like to know how to create a killable NPC enemy character?
At a very basic level, you'd need to have a script on your NPC which has a variable containing its current amount of health, and a function which is designed to be called by other weapons or hazards, which reduces this health value.
This function would then be responsible for reducing the health value, and killing and removing the NPC when its health reaches zero.
For example:
var health = 100.0;
function ApplyDamage( amount : float ) {
health -= amount;
// <- (update on-screen health displays here)
if (health < 0) {
Die();
} else {
// <- (play "hurt" animation & sound here)
}
}
function Die() {
// <- (play "die" animation & sound)
yield WaitForSeconds( dieDuration );
// now remove this gameObject from the scene:
Destroy(gameObject);
}