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.
3 Answers
3This 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’.
This is my complete fix. This should remove all the errors. var waitTime : int = 0.5; var immune : boolean = false; var timeExisted : int; var playerHp = 10; //or whatever you want. function Update () { if (Time.time > waitTime + timeExisted){ immune = false; } } function OnCollisionEnter ( c : Collider ) { if (c.gameObject == "Zombie" && immune == false) { playerHp = playerHp - 10; timeExisted = Time.time; immune = true; } } Hope this works. make no edits. tell me it it works.
– TpaleyIt works but how do I get my zombies to damage and kill him? Such as set the damage the zombies do. Something like a zombie can attack once per second, it does 10 damage, and its range is 1?
– Frosty96try 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
so do i only put this on the player? dont have to add anything to zombies?
– Frosty96Thought i had it but these errors appeared Assets/PlayerTakeDamage.js(15,18): BCE0022: Cannot convert 'float' to 'boolean'. Assets/PlayerTakeDamage.js(13,43): BCE0051: Operator '-' cannot be used with a left hand side of type 'System.Type' and a right hand side of type 'int'. Thanks for all the help this part is out of the field of what I know.
– Frosty96