Answer the question
In order to leave comments, you need to log in
What can reset the values of variables?
I threw out everything superfluous from the script and left only the debug and this is what I saw
public class Cell : MonoBehaviour {
public int X, Y;
public Move = false;
void OnMouseDown(){
Move = true;
}
void Update(){
if(Move) Debug.Log(X + "," + Y);
}
}
#-----------------------------------------------------
public class Board : MonoBehaviour {
public Dictionary<(int, int), GameObject> Cells = new Dictionary<(int, int), GameObject>();
void Start(){
CreateBoard();
}
void CreateBoard(){
for(int y = 0; y < 5; y++){
for(int x = 0; x < 5; x++){
GameObject PrefabResources = Resources.Load("Prefabs/test", typeof(GameObject)) as GameObject;
Cells[(x, y)] = Instantiate(PrefabResources, new Vector3(x, y, 0), Quaternion.identity) as GameObject;
Cells[(x, y)].AddComponent<Cell>();
Cells[(x, y)].GetComponent<Cell>().X = x;
Cells[(x, y)].GetComponent<Cell>().Y = y;
}
}
}
}
3.5
0.0
3.5
0.0
3.5
0.0
............
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question