public GameObject[] buttons
на кнопках висит скрипт Button, мне нужна обращаться к элементу Image скрипту Button далее у меня везде так
Синтаксис:
Используется csharp
public void ButtonClickDown()
{
for (int i = 0; i < buttons.Length; i++)
{
if (buttons[i].GetComponent<Button>().id == currentId)
{
buttons[i].GetComponent<Image>().color = buttons[i].GetComponent<Button>().selectedColor;
switch (currentId)
{
case 1:
SlotCraftEnable();
break;
}
switch (currentId)
{
case 2:
SlotHandsEnable();
break;
}
foreach (GameObject item in slotItem)
{
item.GetComponent<Image>().color = buttons[i].GetComponent<Button>().selectedColor;
}
}
if (buttons[i].GetComponent<Button>().id != currentId)
{
buttons[i].GetComponent<Image>().color = disableColor;
buttons[i].GetComponent<Button>().enabled = false;
}
}
}
{
for (int i = 0; i < buttons.Length; i++)
{
if (buttons[i].GetComponent<Button>().id == currentId)
{
buttons[i].GetComponent<Image>().color = buttons[i].GetComponent<Button>().selectedColor;
switch (currentId)
{
case 1:
SlotCraftEnable();
break;
}
switch (currentId)
{
case 2:
SlotHandsEnable();
break;
}
foreach (GameObject item in slotItem)
{
item.GetComponent<Image>().color = buttons[i].GetComponent<Button>().selectedColor;
}
}
if (buttons[i].GetComponent<Button>().id != currentId)
{
buttons[i].GetComponent<Image>().color = disableColor;
buttons[i].GetComponent<Button>().enabled = false;
}
}
}
везде вообщем GetComponent мне кажется как то это неправильно, может можно как-то указать в функции Старт GetComponent ?