I'm working on a crossword puzzle game. In order to set the letters in my tiles, I have a script attached to text components that accessing a char array that stores my letters. It looks like this:
First class:
public class GenerateBoard : MonoBehaviour
{
public static char[,]gameBoard = new char[15,15];
void Start()
{
gameBoard[0, 0] = 'W';
}
Second class:
public class SetLetter : MonoBehaviour
{
Text letter;
public int x;
public int y;
// Start is called before the first frame update
void Start()
{
letter = GetComponent<Text>();
letter.text = GenerateBoard.gameBoard[x,y] + "";
}
// Update is called once per frame
void Update()
{
Debug.Log("glitch: " + GenerateBoard.gameBoard[0, 0]);
}
}
I would expect Debug.Log to print 'W' but it appears to be empty. Why isn't it accessing the letter 'W' from the first class? When I use Debug.Log in my first class it properly prints 'W'.
Debug.Log
gets called before the first script gets the chance to initialized, Here I am assuming you also attached the first script to GameObject as well \$\endgroup\$ – Digvijaysinh Gohil Apr 15 '19 at 6:19