using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyAttack : MonoBehaviour
{
public int nulldamage = 0;
public float attackDelay = 10;
float lastAttacked = -999;
public int attackDamage = 2;
Animator anim;
GameObject player;
PlayerHealth playerHealth;
//float timer;
//public float attackRate = 0f;
//EnemyHealth enemyHealth;
// Use this for initialization
void Awake()
{
player = GameObject.FindGameObjectWithTag("Player");
playerHealth = player.GetComponent();
//enemyHealth = GetComponent ();
anim = GetComponent();
}
// Update is called once per frame
void OnTriggerStay(Collider other)
{
if (other.gameObject == player)
{
Attack();
}
}
void Update()
{
if (playerHealth.currentHealth <= 0)
{
Destroy(player);
anim.SetTrigger("PlayerDead");
}
}
private void Attack() //Call this in OnTriggerStay if the colliding gameObject is the player
{
while (Time.time > lastAttacked + attackDelay)
{
anim.SetTrigger("Attack"); //trigger our animation
if (playerHealth.currentHealth > 0)
{
playerHealth.TakeDamage(attackDamage); //make player take damage
}
lastAttacked = Time.time;
}
}
}
↧