- Home /
Accessing Variables Assigned To Prefabs
Ok, I'm currently making a checkers game in Unity and I have managed to get the board and piece made and in their correct positions. The Checkers itself has a Class called 'Piece' and this is where they are Instantiated and variables assigned.
I want to be able to select those checker pieces and access the variables that are allocated to that single piece. I can select the piece through raycast and finding that gameobject through a tag. However, I have variables such as 'isKing' which I would like to access and I am struggling with this.
All Help will be appreciated muchly.
//Instantiates the prefabs of the checker pieces
public void DrawPiece(Vector3 _checkPos, Color _color, int _checkID, bool _isPlayer)
{
//Once Drawn set all initial varaibles
SetPiece (_checkID, _checkPos, _isPlayer);
//Draw and set the Player Checker
selectedChecker = (GameObject)Instantiate(checker, _checkPos, Quaternion.identity);
^^ this is within the Piece class, and the 'SetPiece' just assigns the variables to that prefab.
Comment