Experience Drop On Enemy Kill

Hi. I’ve implemented a leveling system in my game
and i know i just need to call “CurrentXp += x;” on Enemy “Health=0”
but i can’t figure out how to give access in my “Enemy” script to use “CurrentXp”


XPController Script (This is attatched to my experience bar)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class XpController : MonoBehaviour
{

[SerializeField] private TextMeshProUGUI LevelText;
[SerializeField] private TextMeshProUGUI ExperienceText;
[SerializeField] private int Level;
public float CurrentXp;
[SerializeField] private float TartgetXp;
[SerializeField] private Image XpProgressBar;


// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        CurrentXp += 12;
    }

    ExperienceText.text = CurrentXp + " / " + TartgetXp;
    ExperienceController();
}

public void ExperienceController()
{
    LevelText.text = "" + Level.ToString();
    XpProgressBar.fillAmount = (CurrentXp / TartgetXp);

    if(CurrentXp >= TartgetXp) //level up
    {
        CurrentXp = CurrentXp - TartgetXp;
        Level++;
        TartgetXp += 50;
    }
}

}

And then in Enemy script i don’t have access to “CurrentXP” i need to figure out how to do that.

You could use a singleton in the XpController.

public class XpController : MonoBehaviour
{
	public static XpController instance; //Declare a singleton

	private float CurrentXp;

	void Awake ()
	{
		if (instance == null) {
			instance = this; //Assign current instance to the singleton
		}
	}
	public void IncreaseXP(float amount)
	{
		CurrentXp += amount;
	}

}

By using a singleton, the enemies can affect the XP:

XpController.instance.IncreaseXP (x);

I love you.

I watched so many different tutorials and it never really made sense. Also a great help just to know this in general. Tysm!