-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZombieAttack.cs
36 lines (30 loc) · 889 Bytes
/
ZombieAttack.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using UnityEngine;
using System.Collections;
public class ZombieAttack : MonoBehaviour {
public float damage = 50f;
private Animator anim;
private Transform player;
private PlayerHealth playerHealth;
private bool attacking;
private int attackFloat;
void Awake()
{
anim = GetComponent<Animator>();
attackFloat = Animator.StringToHash("Attack");
player = GameObject.FindGameObjectWithTag("Player").transform;
playerHealth = player.gameObject.GetComponent<PlayerHealth>();
}
void Update()
{
float attack = anim.GetFloat(attackFloat);
if (attack > 0.5f && !attacking && playerHealth.health > 0)
AttackPlayer();
if (attack < 0.5f)
attacking = false;
}
void AttackPlayer()
{
attacking = true;
playerHealth.takeDamage(damage);
}
}