the variables zeroX, zeroY take on certain values in the Start () function, they do not change anywhere else. but when the clickButtonNum () function is called, their values are not the same as those resulting from Start (), what could be the problem?
public class UI_Game : MonoBehaviour { public GameObject button, imageParent; GameObject[,] matrixButtons = new GameObject[4, 4]; int[,] modelMatrix = new int[4, 4]; private int zeroX; private int zeroY; void Start () // срабатывает при создании объекта { generateMap (); } private void generateMap() //генерирует поле для игры { int[] num = new int[16]; for (int a = 0; a != 16; a++) //массив с числами для создания модели поля { num [a] = a; } mixArray (num); int index = 0; for (int x = 0; x!=4;x++) { for (int y = 0; y != 4; y++) { if (num [index] != 0) { createButton (x,y,num [index]); modelMatrix [x, y] = num [index]; //запоминаем положение номеров кнопок в модель } else { modelMatrix [x, y] = num [index]; zeroX = x; zeroY = y; } index++; } } } private void createButton(int x, int y, int num) // создает кнопку-фишку с нужным числом в нужных коорднатах { GameObject buttonLink = Instantiate (button); buttonLink.transform.SetParent (imageParent.transform); Vector3 newPosition = new Vector3 (-60 + x * 40, -60 + y * 40); buttonLink.transform.localPosition = newPosition; buttonLink.transform.Find ("Text").GetComponent<UnityEngine.UI.Text> ().text = num.ToString(); buttonLink.transform.GetComponent<Coordinates_button> ().set_x (x); buttonLink.transform.GetComponent<Coordinates_button> ().set_y (y); matrixButtons [x, y] = buttonLink; } private void mixArray(int [] num) // перемешивает числа в массиве { int swapNum = Random.Range (10, 20); for (int a = 0; a != swapNum; a++) { int firstNum = Random.Range (0, 16); int secondNum = Random.Range (0, 16); int bufer = num [firstNum]; num [firstNum] = num [secondNum]; num [secondNum] = bufer; } } public void clickButtonNum() // обратывает нажатие по кнопке-фишке { Debug.Log (zeroX);