Hello,
I want to put an index for each item in the list and every button takes an index of the item and when I press any button it opens up the corresponding panel for the button.
public GameObject ClanDescriptionContainer;
GameObject Descripition = Instantiate(ClanDescriptionPrefab, ClanDescriptionContainer.transform) as GameObject;
cList = new GameObject[ClanDescriptionContainer.transform.childCount];
for (int i = 0; i < ClanDescriptionContainer.transform.childCount; i++)
cList[i] = ClanDescriptionContainer.transform.GetChild(i).gameObject;
foreach (GameObject go in cList)
go.SetActive(false);
}
}
public void Join()
{
cList[index].SetActive(false);
index++;
if (index == cList.Length)
index = 0;
cList[index].SetActive(true);
}
public void SelectButton(int buttonIndex)
{
for (int i = 0; i < cList.Length; ++i)
cList[i].SetActive(i == buttonIndex);
}
I don’t know how can i explain but this video maybe can explain what I mean. I want when I create a Clan. I can move between them when I select his name and click Join clan it opens another panel https://vimeo.com/383448260
public GameObject itemTemplet;
public GameObject content;
int index = 0;
public void ClickBtn()
{
var copy = Instantiate(itemTemplet);
copy.transform.parent = content.transform;
copy.transform.localPosition = Vector3.zero;
copy.GetComponentInChildren<Text>().text = (index + 1).ToString();
int copyOfIndex = index;
copy.GetComponent<Button>().onClick.AddListener(
() =>
{
Debug.Log("Index number : " + copyOfIndex);
}
);
index++;
}
I think it’s about the program structure here…
You don’t need a new panel for every clan you have. One panel it’s just fine, if you want to show more than a clan just duplicate it.
This “join clan” panel should auto complete himself with information based on a index (your button index). You can also send to this clan your clan[index] structure to show.
And with that i think it will be ok.
Also when you’re joining clan
public void Join()
{
cList[index].SetActive(false);
index++;
if (index == cList.Length)
index = 0; //here this line will always execute if you're clicking the last button of the list
cList[index].SetActive(true);
}