Health Bar Script Error

Hello so i have a attack script that make the enemy attack the player. But It seems as if the enemy isnt attacking the player. It will only attack the player if i click and drag the player from the hierarcy and drop it into the place on the script for the transform. but since the enemy is spawned from the project tab, i wont be able to click and drag the player transform onto the script in the hierarcy. So i was wondering what i could do to alter the scripts so that when it spawns from the project tab it will do damage to player.

Attack Script:

using UnityEngine;
using System.Collections;

public class EnemyAttack1 : MonoBehaviour {
public GameObject Player;
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);

if(distance < 2.5f) {
if(direction > 0) {

PlayerHealth1 ph = (PlayerHealth1)Player.GetComponent(“PlayerHealth1”);

ph.AdjustCurrentHealth(-10);
}
}
}

}

PlayerHealth Script:

using UnityEngine;
using System.Collections;

public class PlayerHealth1 : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public int display = 100;

public float healthBarLength;

// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}

// Update is called once per frame
void Update () {
AdjustCurrentHealth(0);
}
;
void OnGUI() {
GUI.Box(new Rect(172, 250, Screen.width / 4, 20), curHealth + "/"  + maxHealth);
GUI.Box(new Rect(172, 255, healthBarLength / 2, 10), display + "/" + curHealth);
}

public void AdjustCurrentHealth(int adj) {
curHealth += adj;

if(curHealth < 0)
curHealth = 0;

if(curHealth > maxHealth)
curHealth = maxHealth;

if(maxHealth < 1)
maxHealth = 1;

healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth); 

}
}

Thanks in Advance

I believe what you need to do is:

  1. Do not play the game stay in edit mode.
  2. Drag the enemy onto the hierarchy.
  3. Drag the player onto the transform.
  4. Delete the enemy in the project folder.
  5. Drag the enemy back into the project folder.
  6. You’re done!

I believe what you need to do is:

  1. Do not play the game stay in edit mode.
  2. Drag the enemy onto the hierarchy.
  3. Drag the player onto the transform.
  4. Delete the enemy in the project folder.
  5. Drag the enemy back into the project folder.
  6. Your done!

I believe what you need to do is:

  1. Do not play the game stay in edit mode.
  2. Drag the enemy onto the hierarchy.
  3. Drag the player onto the transform.
  4. Delete the enemy in the project folder.
  5. Drag the enemy back into the project folder.
  6. Your done!

I believe what you need to do is:

  1. Do not play the game stay in edit mode.
  2. Drag the enemy onto the hierarchy.
  3. Drag the player onto the transform.
  4. Delete the enemy in the project folder.
  5. Drag the enemy back into the project folder.
  6. Your done!

I believe what you need to do is:

  1. Do not play the game stay in edit mode.
  2. Drag the enemy onto the hierarchy.
  3. Drag the player onto the transform.
  4. Delete the enemy in the project folder.
  5. Drag the enemy back into the project folder.
  6. Your done!

I believe what you need to do is:

  1. Do not play the game stay in edit mode.
  2. Drag the enemy onto the hierarchy.
  3. Drag the player onto the transform.
  4. Delete the enemy in the project folder.
  5. Drag the enemy back into the project folder.
  6. Your done!