Enemy drops to much items.

Recently I came up with a loot system for my enemies in an actual project. My player can fight them, take them down and my enemy dies. But as they die they drop the same item as long as the dead delay is going on.
Afterwards I got the null reference error. So I know that I still call the function. The writer of the script,from where I have it, say’d I should use a boolean. But thats where I really suck at. I tried it and failed. To get a better understanding here are the scripts that should work together.

EnemyHealth

using System.Collections;

public class EnemyHealth : MonoBehaviour
{
    public int maxHealth = 100;
    public int curHealth = 100;
    public float deadDelay = 5f;
    private float deadTimer;

    public bool dead = false;


    //this has to be always the same as Damage by the Player
    public int damage = 50;
   
    void Start()
    {
        GetComponent<EnemyMovement> ().enabled = true;
    }

    void Update ()
    {
        AddJustCurrentHealth (0);
    }

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

        if (curHealth < 0)
            curHealth = 0;

        if (curHealth > maxHealth)
            curHealth = maxHealth;

        if (maxHealth < 1)
            maxHealth = 1;
                   
        if (curHealth == 0)
        {
            //Debug.Log("IS DEAD!");
            dead = true;
            GetComponent<EnemyMovement> ().enabled = false;
            GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
            GetComponent<Animation>().Play("Dead");
            deadDelay -= Time.deltaTime;

            if(deadTimer >= deadDelay)
            {
                gameObject.SetActive(false);
            }

            if(dead == true)
            {
                GetComponentInChildren<LootSystem>().calculateLoot();
                //Insert loot here, but only ONE
            }
            //Destroy(gameObject);
        }
    }
}

LootSystem

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


public class LootSystem : MonoBehaviour
{
    [System.Serializable]
    public class DropCurrency
    {
        public string name;
        public GameObject item;
        public int dropRarity;
    }

    public List<DropCurrency> LootTable = new List<DropCurrency>();
    public int dropChance;

    public void calculateLoot()
    {
        int calc_dropChance = Random.Range (0, 101);

        if (calc_dropChance > dropChance)
        {
            return;
        }

        if (calc_dropChance <= dropChance)
        {
            int itemWeight = 0;

            for(int i = 0;i<LootTable.Count;i++)
            {
                itemWeight += LootTable [i].dropRarity;
            }
            Debug.Log("ItemWeight= "+ itemWeight);

            int randomValue = Random.Range(0, itemWeight);

            for(int j = 0;j<LootTable.Count;j++)
            {
                if(randomValue <= LootTable[j].dropRarity)
                {
                    Instantiate(LootTable[j].item, transform.position,Quaternion.identity);
                    return;
                }
                randomValue -= LootTable[j].dropRarity;
            }
        }
    }
}

The only thing I need is that the Enemy is dropping only one item. thanks alot.

First, you should probably also check for a negative value to die.

What’s happening is that the if (curHealth == 0) is evaluated to true every frame, not just the frame when the mob dies.

Change it to something like this, the first if statement should now only be executed once, when the mob dies.

        if (curHealth <= 0 && !dead)
        {
            //Debug.Log("IS DEAD!");
            dead = true;
            GetComponent<EnemyMovement> ().enabled = false;
            GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
            GetComponent<Animation>().Play("Dead");
            GetComponentInChildren<LootSystem>().calculateLoot();
         }
         if (dead)
         {
             deadDelay -= Time.deltaTime;
             if(deadTimer >= deadDelay)
             {
                 gameObject.SetActive(false);
             }
         }

that helped. Thanks alot.