public void OnButtonPressed() { if (isAvailable) { isAvailable = false; isSelected = true; GameObject playerShip = null; GameObject[] ships = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject ship in ships) { if (ship.GetComponent <NetworkIdentity>().isLocalPlayer) { playerShip = ship; } } //ship color playerShip.GetComponent <Ship>().UpdateShipColor(squareColor); playerShip.GetComponent <Player_ID>().TransmitColor(squareColor); playerShip.GetComponent <ColorSquareManager>().TransmitChange(squareID, isAvailable); if (GameController.instance.currentSquareID != -1) { GameObject[] colorSquares = GameObject.FindGameObjectsWithTag("ColorSquare"); foreach (GameObject colorSquare in colorSquares) { if (colorSquare.GetComponent <ColorSquare>().GetID() == GameController.instance.currentSquareID) { ColorSquare colorSquareScript = colorSquare.GetComponent <ColorSquare>(); colorSquareScript.SetIsAvailable(true); colorSquareScript.SetIsSelected(false); colorSquareScript.ChangeLook(); playerShip.GetComponent <ColorSquareManager>().TransmitChange(GameController.instance.currentSquareID, true); } } } GameController.instance.currentSquareID = squareID; ChangeLook(); } }
void PickRandomColor() { GameObject[] colorSquares = GameObject.FindGameObjectsWithTag("ColorSquare"); List <GameObject> availableColors = new List <GameObject>(); foreach (GameObject colorSquare in colorSquares) { if (colorSquare.GetComponent <ColorSquare>().GetIsAvailable() == true) { availableColors.Add(colorSquare); } } ColorSquare randomColorSquare = availableColors[Random.Range(0, availableColors.Count)].GetComponent <ColorSquare>(); randomColorSquare.SetIsSelected(true); randomColorSquare.SetIsAvailable(false); myTransform.gameObject.GetComponent <Ship>().UpdateShipColor(randomColorSquare.squareColor); myTransform.gameObject.GetComponent <Player_ID>().TransmitColor(randomColorSquare.squareColor); myTransform.gameObject.GetComponent <ColorSquareManager>().TransmitChange(randomColorSquare.GetID(), false); GameController.instance.currentSquareID = randomColorSquare.GetID(); randomColorSquare.ChangeLook(); }