NullReferenceException Error

Hey,

I have a problem with my enemyHealth script. I googled the error and found something that i have to make a new instance of the object. Maybe with ’ new Object() ’ or something else but i cant fix it >.<

using UnityEngine;
using System.Collections;

public class enemyHealth : MonoBehaviour
{
    Animator anim;
    enemyMovement enemyMove;
    enemySendDamage enemySendDmg;


    public int currentHealth = 20;
    public int storedExp = 10;
    public float actualTime;
    public Transform enemySprite;

    // Use this for initialization
    void Start()
    { 
        anim = enemySprite.GetComponent<Animator>();
        enemyMove = GetComponent<enemyMovement>();
        enemySendDmg = GetComponent<enemySendDamage>();
    }

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

    void applyDamage(int damage)
    {
        if (currentHealth > 0)
        {
            currentHealth -= damage;
            if (currentHealth < 0)
            {
                currentHealth = 0;
            }

            if (currentHealth == 0)
            {
                enemySendDmg.colObject.SendMessage("applyExp", storedExp);
                die();
            }
            else
            {
                anim.SetTrigger("hit");
            }
        }
    }

    void die()
    {
        enemyMove.enabled = false;
        anim.SetTrigger("hit");
        anim.SetTrigger("die");
        Destroy(gameObject,1.23f);

    }
}

This is the full error message :

NullReferenceException: Object reference not set to an instance of an object
enemyHealth.applyDamage (Int32 damage) (at Assets/Scripts/Enemy/enemyHealth.cs:42)
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
charSendDamage:OnTriggerStay2D(Collider2D) (at Assets/Scripts/Character/charSendDamage.cs:42)

Regards,

LifeArtist

the error says, that at line 42 you are calling something which does not exist or there is no reference to that

i guess that “enemySendDmg” has no “colObject” set

Instead of using enemySendDmg = GetComponent(); i have to use GetComponentInChildren<>();