When I first made my script it worked just fine. Today I came back and it wouldn't let me add the script to anything because of the private error. Here is my entire code and I don't know why it isn't working. Can someone please tell me why it isn't working?
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
public float attackTimer;
public float coolDown;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 0.5f;
}
// Update is called once per frame
void Update () {
if (attackTimer > 0)
attackTimer -= Time.deltaTime;
if (attackTimer < 0)
attackTimer = 0;
if (Input.GetKeyUp (KeyCode.F)) {
if(attackTimer == 0){
Attack();
attackTimer = coolDown;
}
}
private void Attack(){ //<---- This is where the error is
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot (dir, transform.forward);
Debug.Log(distance);
if(distance < 3) {
if(direction > 0) {
EnemyHealth eh = (EnemyHealth)target.GetComponent ("EnemyHealth");
eh.AddjustCurrentHealth (-10);
}
}
}
}
↧