Enemy Health Bar Fill (Unity2D)

So I have a Enemy. I have a enemy script with health and such, and I have a script which deals damage to the enemy, I have a healthbar with fill that is a child of my enemy i wnat it to represent my enemies health so when my enemy takes damage my health bar lowers.

Enemy Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EnemyFollow : MonoBehaviour {

  
    
    public float speed;
  
    public float ehealth;
    
    private Transform target;

	// Use this for initialization
	void Start () {

        EnemyHealthBar = GetComponent<Image>();
       
        
        target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();

 
		
	}
	
	// Update is called once per frame
	void Update () {

        transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
  
        if(Vector2.Distance(transform.position, transform.position) <= 5)
        {
            Debug.Log("Help");
        }


        

        if(ehealth <= 0)
        {
            Die();
            if (HealthBarScript.health < 10)
            {
                HealthBarScript.health += 0.5f;
            }
        }
    
        

    }

    public void Die()
    {
        Destroy(this.gameObject);

    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            Destroy(this.gameObject);
            HealthBarScript.health -= 1f;
        }
        

    }
}

Script that deals damage to enemy

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Projectile : MonoBehaviour {

    private GameObject triggeringEnemy;
    private Vector2 target;
    public float speed;
    public float damage;
   
	// Use this for initialization
	void Start () {
        target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
      
	}
	
	// Update is called once per frame
	void Update () {
        transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime);

        if(Vector2.Distance(transform.position, target) < 0.1f)
        {
            Destroy(gameObject);
        }

    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.tag == "Enemy")
        {
            Destroy(gameObject);    
            triggeringEnemy = other.gameObject;
            triggeringEnemy.GetComponent<EnemyFollow>().ehealth -= damage;
           
        }
    }
}

This should give you an idea of how to deal with it. You hit the space bar, deals damage, reduces the health bar.


using UnityEngine;
using UnityEngine.UI;


/// <summary>
/// Slap this on your health bar object and link the image that has the fill
/// </summary>
public class HealthBar : MonoBehaviour
{
    [SerializeField] Image healthBar;

    float startingHealth = 100f;

    // This property is the main theme here - as it updates it auto updates the health bar
    float currentHealth;
    float CurrentHealth
    {
        get { return currentHealth; }
        set
        {
            currentHealth = value;
            healthBar.fillAmount = currentHealth / startingHealth;
        }
    }

    bool isDead { get { return CurrentHealth <= 0; } }


    void Start()
    {
        CurrentHealth = startingHealth;
    }


    void Update()
    {
        // Just faking damage for testing so you can see how I do it
        // Your damage will be coming from somewhere else
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (isDead == false)
            {
                DealDamage(Random.Range(5f, 25f));
            }
        }
    }


    void DealDamage(float damageAmount)
    {
        CurrentHealth -= damageAmount;
    }
}
  1. I slapped on a EnemyHealthBarScript onto my EnemyHealthBars fill.

  2. The code is like this

    using UnityEngine;
    using UnityEngine.UI;

    public class EnemyHealthBarScript : MonoBehaviour
    {
    Image EnemyHealthBar;

    void Start()
    {
        EnemyHealthBar = GetComponent<Image>();
    
    }
    
    void Update()
    {
        EnemyHealthBar.fillAmount = EnemyFollow.ehealth;
    }
    

    }

`
But I get an error = “An object reference is required to access non-static static member”. I need a little guiding.