How can I get a data from function to other function?

I have this function

   public void InitButtons () {
	
	Transform currentChild;
	for (int i = 0; i < buttonsContainer.childCount; i++) {
		currentChild = buttonsContainer.GetChild (i);
		buttonlist [i / column, i % column] = currentChild.GetChild (0).GetComponent<Text> ();
		currentChild.GetComponent<Buttons> ().buttonIndex = i;

And I want to get the data of “i” variable in other function.
How can I solve this problem ?

You can make “i” a global variable. Your for loop is:

for (i = 0; i < buttonsContainer.childCount; i++)

without the declaration.

It depends on how your other function is accessed. At the end of your for loop your setting buttonIndex from a ‘Buttons’ component to equal i. If the function is within that Buttons script, than you can use buttonIndex within that function in place of “i” as buttonIndex will equal i. That is assuming Buttons is what I think it is, and is some kind of component on every button you initialize, and not something to contain all buttons created.

@Destolos answer is valid to as long as i is indexed by each individual button before i is incremented by the loop.

If neither helps, then without more information I’m not sure what else to add.