Trouble with RPG Health Bar (BurgZergArcade's Tutorial)

hello all,

i’m currently learning how to use unity 3d by following BurgZergArcade’s rpg tutorial. Right now i have the little cube enemies approaching and attacking the player, however, it looks like the player has two health bar boxes layered on top of each other (i apologize if i didn’t get the terminology correct)

my C# script for the player health

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
	public int maxHealth = 100;
	public int curHealth = 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(10, 10, Screen.width / 2 / (maxHealth / curHealth), 20), curHealth + "/" + maxHealth);
	}
	
	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);
	}
}

my C# script for enemies attacking:

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);
		
		if(distance < 2.5f) {
			if(direction > 0) {
				PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
				eh.AdjustCurrentHealth(-10);
			}
		}
			}
}

i have a feeling that it has to do with that last bit of code

			PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
				eh.AdjustCurrentHealth(-10);

but i’m not too sure.

i tried looking through the forums (and continue lurking), however it didn’t seem like anyone else is having this problem, and i paused the video and checked the codes line by line to see if i did something wrong, but it seemed like i copied it perfectly. >_>

thanks for all the help!

nothing wrong with that line. It just gets the PlayerHealth script from the player to use the function AdjustCurrentHealth in there.
some strange things in the scripts but nothing wrong.
make sure you didn’t attach the script twice in your scene.

Hmmm… okay. When i get home i’ll check it to see if there is more than one copy. Come to think of it your solution makes sense…

Do you mind telling me what looks a bit strange in the script? Or would that stuff be too over my head? (This is the first time i’ve used C#, and i’m only familiar with HTML).