private ClickItems getItemClicked() { RaycastHit hit; Rigidbody rb; ClickItems items; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100.0f)) { if (hit.transform != null) { if (rb = hit.transform.GetComponent <Rigidbody>()) { items = new ClickItems(hit, rb, true); return(items); } } } items = new ClickItems(new RaycastHit(), new Rigidbody(), false); return(items); }
// Update is called once per frame void Update() { if (aiON && aiMove) { return; } if (numGambles == 4) { updateTooltips("GLHF"); } // Check if gameover gameOver(); // Run if ai's turn if (playerTurn == PlayerColors.Blue && aiON) { gs.toggleTankRings(redTanks, new CoordinateSet(-1, -1), false); gs.toggleTankRings(blueTanks, new CoordinateSet(-1, -1), false); //handleGreedyAi(); if (aiMove == false) { aiMove = true; if (currentLevel == Levels.Level1) { StartCoroutine(handleGreedyAi()); } else { StartCoroutine(handleMinMaxAi()); } } } // Skip turn if spacebar is pressed if (Input.GetKeyDown(KeyCode.Space) && !aiMove) { round++; TileHighlighter.resetTiles(); if (round == Rounds.Gamble) { gs.toggleTankRings(playerTurn == PlayerColors.Red ? redTanks : blueTanks, new CoordinateSet(-1, -1), true); gs.toggleTankRings(playerTurn == PlayerColors.Red ? blueTanks : redTanks, new CoordinateSet(-1, -1), false); updateTooltips("Gamble"); gs.updatePlayerPowerupState(playerTurn); } if (round == Rounds.Attack) { gs.toggleTankRings(redTanks, new CoordinateSet(-1, -1), false); gs.toggleTankRings(blueTanks, new CoordinateSet(-1, -1), false); updateTooltips("Attack1"); } if (round > Rounds.Gamble) { round = Rounds.Move; updateTooltips("Move1"); numGambles++; changeTurns(); } printTurn(); } // If nothing has been clicked, return if (oc.objectClicked == null) { return; } // Assign variables objectClicked = oc.objectClicked; oc.objectClicked = null; ClickItems items = getItemClicked(); RaycastHit hit = items.getRaycastHit(); if (!items.isValid()) { return; } switch (round) { case Rounds.Move: handleMove(hit); break; case Rounds.Attack: assignTanksClicked(hit); handleAttack(true); break; case Rounds.Gamble: handleGamble(hit); break; } gs.updatePlayerHealthBars(hpController); }