Hi, i’m making a zombie game and i already have the spawners completed and the zombies follow me but i have no idea how to make them hurt the player. The player life is made and i can kill the zombies i just need them to be able to kill me. Any help is appreciated! thx.
This is javascript.
maybe have something like this for the player:
var waitTime : int; //# of seconds to wait before they can hurt you again.
var immune : boolean = false; //DO NOT EDIT
var timeExisted : int; //DO NOT EDIT
function Awake () {
if (Time.time > waitTime + timeExisted){
immune = 0;
}
}
function OnCollisionEnter ( c : collider ) {
if (c.gameObject == "Zombie" && immune == 0) {
playerHp = playerHp - 5;
timeExisted = Time.time;
immune = 1;
}
}
Hope that helps!
acutally that comment ended odd here is what i did
var waitTime : int = 0.5;
var immune : boolean = false;
var timeExisted : int;
function Awake () {
if (Time.time > waitTime + timeExisted){
immune = 0.5;
}
}
function OnCollisionEnter ( c : SphereCollider ) {
if (c.gameObject == “Zombie” && immune == 0.5) {
playerHp = playerHp - 10;
timeExisted = Time.time;
immune = 0.5;
}
}
And i got these errors
Assets/PlayerTakeDamage.js(7,18): BCE0022: Cannot convert ‘float’ to ‘boolean’.
Assets/PlayerTakeDamage.js(13,20): BCE0005: Unknown identifier: ‘playerHp’.
Assets/PlayerTakeDamage.js(15,18): BCE0022: Cannot convert ‘float’ to ‘boolean’.
try this
player has this function
void Damage(int damageDealt)
{
int Health-= damagedealt
}
Zombie has this Function
int damage
void OnCollisionEnter(Collider)
{
if (collider.gameObject == "player)
SendMessage(“Damage”,damage,RecieverNotRequired)
}
check here for further details