#Attack();无法调用
#using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAttact : MonoBehaviour {
public int attackDamage = 10;
public float timeBetweenAttck = 0.5f;
private GameObject player;
private PlayerHealth playerHealth;
private bool playerInRanger;
private float time;
private void Awake()
{
player = GameObject.FindGameObjectWithTag("Player");
playerHealth=player.GetComponent();
}
private void onTriggerEnter(Collider other)
{
if (other.gameObject == player)
playerInRanger = true;
}
private void OnTriggerExit(Collider other)
{
if(other.gameObject == player)
playerInRanger= false;
}
void Update () {
if (playerInRanger&&time>=timeBetweenAttck&&playerHealth.currentHealth>=0)
{
time = time + Time.deltaTime;
Attack();
}
}
private void Attack()
{
time = 0;
playerHealth.TakeDamage(attackDamage);
}
}