Problem counting with OnTriggerEnter2D (Conway's Game of Life)
Hi guys. I'm trying (as a challenge) to make Conway's Game of Life. I have all the logic already coded but I'm facing a problem with counting the adjacent "cells". I won't post the entire code because I think it's not relevant to the problem, even if I comment everything it still doesn't work as it should. I'm using a Canvas with panels as the cells, and checking with OnTriggerEnter2D the adjacent cells' state. Every cell has a "isAlive" bool and a "aliveNeighbours" int. Problem: the aliveNeighbours is counting ALL the alive cells in the grid, not just the ones "colliding" with them. If I set the top left cell to alive and the rest are dead, all the dead ones (even the bottom right) have 1 aliveNeighbours. The only thing that I thought could be happening is that the collider is connecting all of them? I mean, are them all adjacent "by extension"?. I hope someone can help me. This is the relevant code:
public bool isAlive;
public int aliveNeighbours = 0;
Cell thisCell;
void Start(){
thisCell = gameObject.GetComponent<Cell>();
}
void OnTriggerEnter2D(Collider other){
if(other.gameObject.GetComponent<Cell>().isAlive){
thisCell.aliveNeighbours++;
}
}