Hi,
I have a game that allows me to place rooks on a chess board by clicking on the game squares. I would like to change my game so that I can place either rooks or pawns. I made some UI buttons called “rook” and “pawn”. I would like it that when I click the rook button, my game remembers it, and then the after that it places rooks on the board until such as time as when I click the pawn button. Then the game will place pawns etc.
My question though, is what is the best way to store this information? Here is some code I wrote, as sort of an experiment:
using UnityEngine;
using System.Collections;
public class GameScript : MonoBehaviour {
private int piece = 0;
public int getPiece()
{
return piece;
}
}
The code that places the chess pieces (and therefor needs the information of which piece to place):
using UnityEngine;
using System.Collections;
public class PlaceChessPieces : MonoBehaviour {
public GameObject piece;
private GameScript data;
void Start () {
Debug.Log("A instance of PlaceChessPieces was initialized");
piece = Resources.Load("rookPiecePrefab") as GameObject;
GameScript data = new GameScript();
}
void OnMouseDown()
{
if(data.getPiece() == 0)
{
Instantiate(piece, transform.position + new Vector3(0, 0.5f, 0), Quaternion.Euler(-90, 0, 0));
}
//Instantiate(piece, transform.position + new Vector3(0,0.5f,0), Quaternion.Euler(-90, 0, 0));
}
}