How do I asign this script to a button successfully?

I have a script on a card gameobject that works perfectly if i place an event trigger to click on the card, it will then randomize it’s heirachy amongst other cards in the deck area. I want to now shift this function onto a UI button, so when i click the button it perform the action when the card is in the deck area.

this is the current script on the gameobject:

public class ShuffleDeck : MonoBehaviour
{
    GameObject Deck;
    public bool isShuffleable = false; 
    int indexNumber;

    private void Start()
    {
        Deck = GameObject.Find("Deck");
    }
   
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Deck")
        {
            isShuffleable = true;
        }
    }
    private void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Deck")
        {
            isShuffleable = false;
        }
    }
    public void Shuffle()
    {
        indexNumber = Random.Range(0, 10);
        if (isShuffleable)
        {
            transform.SetSiblingIndex(indexNumber);
        }
        
    }
    
}

Thanks in advance :slight_smile:

Drag your object into onclick area in the editor and then you can select Shuffle function from there
Make sure function is public.