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);
}
}
}