- Home /
Question by
chandrazack · Feb 09 at 06:29 PM ·
c#buttonarray
Button array c#
I tried to create an array of buttons, but the result is always 7 or the number of buttons, so can I get the results in the order of the buttons? thanks
public class literasi : MonoBehaviour
{
public Button Button;
public int numLiterasi;
float x = 0, y = 0;
// Start is called before the first frame update
void Start()
{
x = -45;
y = 120;
for (int i = 0; i <= 6; i++)
{
if (i % 2 == 0)
{
x = 45;
}
else
{
x = -45;
}
if (i % 2 == 1 && i >= i - 2)
{
y = y - 60;
}
Button btnClone = Instantiate(Button, new Vector2(x, y), Button.transform.rotation);
btnClone.transform.SetParent(GameObject.FindGameObjectWithTag("scrollView").transform, false);
btnClone.GetComponent<Button>().onClick.AddListener(
() => { Space(i); }
);
}
}
// Update is called once per frame
void Update()
{
}
public void createButton(int btnSum)
{
}
private void Space(int tmp)
{
Debug.Log("ID = " + tmp);
}
}
Comment