its C# and when my enemy walks up to me and is in hitting distance it does nothing
using UnityEngine;
using System.Collections;
public class EnemyMelee : MonoBehaviour {
public GameObject target;
public float attackTimer;
public float coolDown;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 2.0f;
}
// Update is called once per frame
void Update () {
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
if(attackTimer == 0)
Attack();
attackTimer = coolDown;
}
private void Attack() {
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
float distance = Vector3.Distance(target.transform.position, transform.position);
if(distance < 3f){
if(direction > 0) {
PlayerHealth eh = (PlayerHealth)target. GetComponent("PlayerHealth");
eh.AdjustcurrentHealth(-10);
}
}
}
}