NullReferenceException

NullReferenceException: Object reference not set to an instance of an object EnemyAttack.Attack () (at Assets/Scripts/EnemyAttack.cs:43) EnemyAttack.Update () (at Assets/Scripts/EnemyAttack.cs:25) After i hit play and the evil cube tries to attack me

basicli i m learning from the berg zerg arcade tutorials and i’ve been good so far but now i get this error
NullReferenceException: Object reference not set to an instance of an object EnemyAttack.Attack () (at Assets/Scripts/EnemyAttack.cs:43) EnemyAttack.Update () (at Assets/Scripts/EnemyAttack.cs:25)
After i hit play and the evil cube tries to attack me
here is my script please help me

using UnityEngine;
using System.Collections;

public class EnemyAttack : 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() {;
			
		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(direction);
		
		if(distance < 2.5f) {
			if(direction > 0) {
		
	PlayerHealth ph = (PlayerHealth)target.GetComponent("EnemyHealth");
	ph.AddjustCurrentHealth(-10);
								}	
							}
						   }
					}

The line number of the error is telling you that it hasn’t found PlayerHealth ph. There probably isn’t one on your target. You should build in protections for this kind of thing so that you never get error messages, and so that you can handle cases where a component you’re looking for isn’t found.

    PlayerHealth ph = (PlayerHealth)target.GetComponent("EnemyHealth");
    if (ph != null)
        ph.AddjustCurrentHealth(-10);
    else
        // do something if PlayHealth is not found

Probably you’ve already solved your problem. And I was having this same problem just a few minutes ago (using the same tutorials). In my case it was because the script for the class PlayerHealth.cs was not directly on the Player object it was inside Graphics which is inside de Player object I just moved the PlayerHealth.cs script directly to the Player object and the error did no repeat.