Hi,
I'm willing to create a Nine men's morris game on Unity (new to it) and I am struggling with the fact that the board of the game isn't a grid of "places" where a piece can move onto (i.e. chess, checkers games). Instead, I'm considering writing an 2d array of vectors3 that contain the 24 places where a piece can go onto. Not sure if this is a good idea nor how exactly to implement it, does anyone have an idea ?
For now what my code does is instantiate the white and black pieces and transform their position as to put them on both sides of the board depending on their color. I've also implemented the mouse over thing. Thanks so much for your help!
Here's my code:
using UnityEngine;
using System.Collections;
public class BoardScript : MonoBehaviour
{
public PieceScript[] pieces =new PieceScript[18];
public GameObject whitePiecePrefab;
public GameObject blackPiecePrefab;
public Vector3 leftSide =new Vector3 (-6.0f,0,-4.0f);
public Vector3 rightSide =new Vector3 (6.0f,0,-13.0f);
private Vector2 mouseOver;
//Use this for initialization
private void Start ()
{
GenerateBoard();
}
private void Update()
{
UpdateMouseOver ();
Debug.Log (mouseOver);
}
private void UpdateMouseOver()
{
RaycastHit hit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),o ut hit,25.0f, LayerMask.GetMask("Board")))
{
//iinteger values, no decimals
mouseOver.x =(int)hit.point.x;
mouseOver.y =(int)hit.point.z;
}
}
private void GenerateBoard()
{
//generate pieces: 0 to 8 white / 9 to 17 black
for(int i =0; i <18; i++){
GeneratePiece (i);
}
}
private void GeneratePiece(int i)
{
bool isWhite =(i <9)?true:false;
GameObject go = Instantiate((isWhite)? whitePiecePrefab : blackPiecePrefab)as GameObject;
go.transform.SetParent (transform);
PieceScript p = go.GetComponent<PieceScript>();
pieces = p;
MovePiece (p, i);
}
private void MovePiece(PieceScript p,int i)
{
bool isWhite =(i <9)?true:false;
p.transform.position =(isWhite)?((Vector3.forward * i)+ leftSide):((Vector3.forward * i)+ rightSide);
}
}
chrisgregan
Thu, 12 Jan 2017 17:08:48 GMT
Hi twister013. The forum here is intended for helping with Fungus related issues rather than general Unity questions. Maybe try the Unity forums?