How do I access Enemy current health variable in another script

I have 2 scripts for my enemies health one which handles hits to the body and im trying to make another script that handles shots to the head basically I want this headhsot script to reduce the enemies current health by 10 however I can’t access the current health in this headshot script it says it doesnt exist.

Here are the scripts:

this is the main health script for handling body shots

    using UnityEngine;
    using System.Collections;
    
    public class enemyHealth : MonoBehaviour {
        public int enemyStartingHealth = 20;
        public int enemyCurrentHealth;
    
    	// Use this for initialization
    	void Start () {
    
            gameObject.SetActive(true);
            enemyCurrentHealth = enemyStartingHealth;
    	}
    
        public void OnCollisionEnter(Collision Bodyshot)
        {
            if (Bodyshot.gameObject.tag == "Bullet")
            {
                enemyCurrentHealth = enemyCurrentHealth - 5;
            }
            
        }
    
    
        public void Update()
        {
            if (enemyCurrentHealth == 0)
            {
                gameObject.SetActive(false);
                Destroy(gameObject);
               
                
            }
        }
    }

This is what my headshot script currently is 

using UnityEngine;
using System.Collections;

public class Headshot : MonoBehaviour {
    enemyHealth enemyHealth = enemyHealth.GetComponent<enemyHealth>().enemyCurrentHealth;

    // Use this for initialization
    void Start()
    {


    }

    void Update()
    {


    }

    public void OnCollisionEnter(Collision Headshot)
    {
        if (Headshot.gameObject.tag == "Bullet")
        {
            enemyCurrentHealth = enemyCurrentHealth - 10;
        }

    }
}

the problem is that enemyCurrentHealth doesnt exist on the headshot script and Im trying to access it and edit it via this script so that if the enemy is hit in the head their health is reduced by 10 rather then 5 for a bodyshot.

Greatly appreciate any help.

First, it’s good practice to always capitalize your Class names. enemyHealth should be EnemyHealth, to disambiguate ‘enemyHealth’ the instance of your class and ‘enemyHealth’ the class itself. Right now, in your Headshot class, you’re trying to call a variable a class name, and it’s telling you that the class doesn’t have a component ‘enemyHealth’.

Second, you need to get a reference to the GameObject that the EnemyHealth script is attached to in order to get the component from it. Right now, you’re trying to get a class’s component, and classes don’t have components.

Third, you’re naming your Collision the same thing as your class - Headshot. That’ll mess you up, name it something generic like ‘col’, since you’re only using that variable in the context of OnCollisionEnter(). You should do that in EnemyHealth, too - variables assigned in the function declaration shouldn’t be named things that you might define elsewhere (like a class named Bodyshot, for instance).

So, long story short, your Headshot script should look something like

using UnityEngine;
using System.Collections;

public class Headshot : MonoBehaviour {
    private EnemyHealth enemyHealth;
    public GameObject enemyObject; // Drag your enemy GameObject into this field in the inspector, the same GameObject that has EnemyHealth on it.

    // Use this for initialization
    void Start()
    {
        enemyHealth = enemyObject.GetComponent<EnemyHealth>();
    }

    public void OnCollisionEnter(Collision col) // You were naming your collision the same name as your class, Headshot - that'll mess you up.
    {
        if (col.gameObject.tag == "Bullet")
        {
            enemyHealth.enemyCurrentHealth -= 10; // Subtracts ten from the variable's value.
        }

    }
}

If I get your point correctly, you will need to keep a reference to enemyHealth script in Headshot.

This will be your headshot script:

public class Headshot : MonoBehaviour {
     enemyHealth enemy_health;
 
     // Use this for initialization
     void Start()
     {
 enemy_health = the_object_that_has_enemyHealth_script.GetComponent<enemyHealth>();
 
     }
 
     public void OnCollisionEnter(Collision Headshot)
     {
         if (Headshot.gameObject.tag == "Bullet")
         {
             enemyHealth.enemyCurrentHealth -= 10;
         }
 
     }
 }

Hi in “Headshot” Script first Define a variable by that script name like this;

public enemyHealth HealthScriptOfEnemy;

then assign the script in head of enemy GameObject to this object via inspector and then u can access that script like these;

HealthScriptOfEnemy.enemyCurrentHealth -= 10;

and there is another problem with your code here u cant use your script name in
OnCollisionEnter( ) , u should use it like this :

       public void OnCollisionEnter(Collision other)
         {
             if (other.gameObject.tag == "Bullet")
             {
     HealthScriptOfEnemy.enemyCurrentHealth -= 10;
             }
     
         }