public void RpcStartGame() { //Make World disapear GameObject.Find("World").GetComponent <Renderer>().enabled = false; GameObject mWorld = GameObject.Find("World"); foreach (Transform child in mWorld.transform) { if (child.name == "Wall") { child.GetComponent <WallDespawner>().StartFalling(); } else if (child.name == "player1Spawn" || child.name == "player2Spawn") { child.gameObject.SetActive(false); } } //Change colors of units mUnitController.SetUnitColors(); //Tell Unit controller it can now let user move units UnitControlScript CS = GameObject.Find("UnitController").GetComponent <UnitControlScript>(); CS.SetMode(3); //Tell the Battle controller to start if (isServer) { BattleControlScript BS = GameObject.Find("BattleController").GetComponent <BattleControlScript>(); BS.StartBattle(true); } }
void Update() { RaycastHit hit; Ray ray; if (Input.GetMouseButtonDown(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100.0f, layerMaskUnits)) { realSelected = hit.collider.gameObject; if (realSelected.GetComponent<UnitControlScript>() && realSelected.GetComponent<UnitControlScript>().owner == activePlayer.playerColor) { selected = realSelected.GetComponent<UnitControlScript>(); writeSelected(); HilightTiles(selected.posX, selected.posY, selected.remainingMoves + 1); } else if (realSelected.GetComponent<ChateauScript>() && realSelected.GetComponent<ChateauScript>().owner == activePlayer.playerColor) { chateauSelected = realSelected.GetComponent<ChateauScript>(); writeChateau(); } else StartCoroutine(clearSelected()); } else if (Physics.Raycast(ray, out hit, 100.0f, layerMaskTiles)) { coords[0] = (int)hit.transform.position.x; coords[1] = (int)hit.transform.position.z; StartCoroutine(clearSelected()); } else StartCoroutine(clearSelected()); } if (Input.GetMouseButtonDown(1) && selected != null) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100.0f, layerMaskTiles)) { selected.moveTo((int)hit.transform.position.x, (int)hit.transform.position.z); writeSelected(); } } }
// Use this for initialization void Start() { selected = null; layerMaskUnits = 1 << 8; layerMaskTiles = 1 << 9; foreach (ChateauScript chateau in FindObjectsOfType<ChateauScript>()) { if (chateau.owner == "red") chateauRed = chateau; else chateauGreen = chateau; } }
IEnumerator<WaitForSeconds> clearSelected() { yield return new WaitForSeconds(0.5f); ShutdownTiles(); detonateButton.SetActive(false); selectedPanel.SetActive(false); castlePanel.SetActive(false); realSelected = null; chateauSelected = null; selected = null; }