I’ve been using Unity for a few years now, and while I can start off a project well I always seem to run into the same issues that make me feel like I’m not using it correctly.
For example, I’ve gone back to basics and I’m trying to create a simple Minesweeper game. If I were creating this anywhere else I’d define each square as an object with different properties and methods like mined, number of neighbour mines, reveal, explode, etc. In Unity, I’ve got prefab models for all the graphics. I’ve got a script that’s attached to the camera that sets up the grid and it all looks fine. I’ve got a script attached to the tile prefab that has methods like Reveal. But now that I’m trying to get things to interact with each other, I’m really struggling.
For example, I’d love to have the tiles in an array and then use recursion for reveals: (pseudo code so don’t focus on it)
public void Reveal() {
renderer.enabled = false;
if (tiles[x-1,y].value == 0 ) { // repeat for all other neighbours
tiles[x-1,y].Reveal();
}
}
But I can’t just do that because the tile is a GameObject and I can’t talk directly to the code. I can probably do it through the Inspector and dragging and dropping the script into a public variable, or using GetComponent and types, but it doesn’t seem like the right way to go. What would be really simple in plain JavaScript, for example, takes a lot more effort in Unity.
What’s the secret sauce that I’m missing? Can someone help me have that ding moment where it all slots together?