I am currently working on a 2d board game. My logic is as follows:
A player will click on a card, then a gamepiece will flash where the player can move. When the player moves there, a list will be updated with the current position.
What I’m having problems with is when I click on a piece, that individual piece with a script called MakeMove only get’s updated, while all other pieces do not update.
Here is what I have:
void OnMouseOver()
{
if (Input.GetMouseButtonDown(0) && gameObject.tag == "Card")
{
setCard(gameObject);
}
else if (cardName != null)
{
if (Input.GetMouseButtonDown(0) && gameObject.tag == "BlueHome")
{
if (hPos0.GetComponent<SpriteRenderer>().color.Equals(getColor("blue")) && IsStartEmpty())
{
moveOutOfHome(0, 0, "blue", cardName);
isHomeEmpty = false;
}
else if (hPos1.GetComponent<SpriteRenderer>().color.Equals(getColor("blue")) && IsStartEmpty())
{
moveOutOfHome(1, 0, "blue", cardName);
isHomeEmpty = false;
}
else if (hPos2.GetComponent<SpriteRenderer>().color.Equals(getColor("blue")) && IsStartEmpty())
{
moveOutOfHome(2, 0, "blue", cardName);
isHomeEmpty = false;
}
else if (hPos3.GetComponent<SpriteRenderer>().color.Equals(getColor("blue")) && IsStartEmpty())
{
moveOutOfHome(3, 0, "blue", cardName);
isHomeEmpty = false;
}
else
{
}
}
else if (Input.GetMouseButtonDown(0) && gameObject.tag == "PlaceHolder" && !(gameObject.GetComponent<SpriteRenderer>().color.Equals(getColor("white"))))
{
Debug.Log(cardName);
makeMove(Int32.Parse(getCardAsString()), hColor);
}
else if (Input.GetMouseButtonDown(0))
{
Debug.Log(gameObject.tag.ToString());
}
}
}
public void moveOutOfHome(int initialPos, int finalPos, string color, GameObject card)
{
click = gameObject;
card = cardName;
GameObject initialP = homePositions[initialPos];
initialP.GetComponent<placeHolderPrefab>();
initialP.GetComponent<SpriteRenderer>().color = getColor("white");
GameObject finalP = placeHolderPositions[finalPos];
finalP.GetComponent<placeHolderPrefab>();
finalP.GetComponent<SpriteRenderer>().color = getColor("blue");
Destroy(cardName);
setActivePositionsList();
}
public void setActivePositionsList()
{
placeHolderPositions = GameObject.FindGameObjectsWithTag("PlaceHolder");
homePositions = GameObject.FindGameObjectsWithTag("BlueHome");
for (int i = 0; i < placeHolderPositions.Length; i++)
{
if (placeHolderPositions*.GetComponent<SpriteRenderer>().color.Equals(getColor("blue")))*
{
activePositionsList.Add(i);
}
}
}