I try to make my frist game in Unity (checkers) but i ran into a problem i dont unterstand
var spawnedStone = Instantiate(_stonePrefab, new Vector3(x, y, -1), Quaternion.identity);
spawnedStone.name = $"Stone {stone}";
if (y <= 2) _iswhite = true;
else _iswhite = false;
spawnedStone.Init(_iswhite);
stone++;
public class Stone : MonoBehaviour
{
[SerializeField] private Color _black, _white;
[SerializeField] private SpriteRenderer _spriteRenderer;
public void Init(bool _iswhite)
{
_spriteRenderer.color = _iswhite ? _white : _black;
}
}
I am trying to call my Init
method of my checkers stone but it does not work somehow but it worked with my tiles for the board
var spawnedTile = Instantiate(_tilePrefab, new Vector3(x, y, 0), Quaternion.identity);
spawnedTile.name = $"Tile {x} {y}";
var _isOffset = (x+y) % 2 == 1;
spawnedTile.Init(_isOffset);
public class Tile : MonoBehaviour
{
[SerializeField] private Color _baseColor, _offsetColor;
[SerializeField] private SpriteRenderer _renderer;
[SerializeField] private GameObject _highlight;
public void Init(bool isOffset)
{
_renderer.color = isOffset ? _offsetColor : _baseColor;
}
anyone knows why ?
this is the error
Thx in advance