Como coloco um botão clone para excluir ele mesmo?

I’m sorry if it’s a stupid question, but I’m making a menu, in it the person can add players name, so I created an object with an inputfield and a button to delete if you want. You can add multiple players and this will instantiate multiple objects with the input and button inside. How can I put the function on the button so when I click it it deletes the object it is child to?

using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Linq;

public class EditarJogadores : MonoBehaviour
{   
        // Instancia e Hierarchy
    public GameObject Filho;
    public Transform Pai;

    public GameObject Parent;

    public RectTransform BotaoFixo;
    // Start is called before the first frame update
    void Start()
    {
        AdicionarNovoJogador();
    }

    // Update is called once per frame
    void Update()
    {
        TouchScreenKeyboard.hideInput=true;
        
    }
    public void AdicionarNovoJogador(){
        // Adcionando Objeto e colocando ele como filho de outro
        GameObject InstantiatedGameObject= Instantiate(Filho);
        InstantiatedGameObject.transform.SetParent(Pai);
        BotaoFixo.SetAsLastSibling(); // Fixar botão em ultimo na Hierarchy do grupo
    }
    public void ExcluirJogador(){
        Transform parentTransform = Parent.transform;
        int numberChildren = parentTransform.childCount-1;

        for(int i = 0; i < numberChildren; i++)
        {
            int index = parentTransform.GetChild(i).GetSiblingIndex();
            Parent.transform.GetChild(i).name = "Jogador"+i;
            Debug.Log(index);
        }
    }
}

Hello there!

I’m not sure what are you trying to delete, but you need the function

Destroy(GameobjectToDestroy);

If you want to destroy the gameobject that contains the script, would be

Destroy(gameObject);

If want to destroy a child of the gameobject that contains the script would be;

Destroy(gameObject.transform.Find("string name of the Child");

Or imagine you have stored the object you want to destroy in a GameObject variable inside the sme script

public GameObject ButtonToDestroy; (And assign it in Inspector)

Destroy(ButtonToDestroy);

Rememebr that Destroy() destroys the gameobject t the end of the frame.

Bye!!