I have been following the BurgZergArcade tutorials for making a Hack n Slash game. I’m on tutorial number 5, "Unity3d tutorial - Melee 1/3. I have copied all the code he wrote exactly, and there are no errors, but when I click the “F” key nothing happens. After some research I’ve noticed its a common problem, but i found no answers. Can someone please help me?
PlayerAttack.cs Code:
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.F)) {
Attack();
}
}
private void Attack() {
float distance = Vector3.Distance(target.transform.position, transform.position);
Debug.Log (distance);
if(distance < 2.5f) {
EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
eh.AddjustCurrentHealth(-10);
}
}
}