//-1 = itself public void Remove(Vector2Int position, int direction) { Tile[] bordering = GameManager.GetGameManager().GetBorderingTiles(position); if (direction == -1) { for (int i = 0; i < 4; i++) { if (bordering[i] == null) { continue; } Tile tile = bordering[i]; if (tile.building != null) { GameObject building = tile.building; CableManager cableManager = building.GetComponent <CableManager>(); switch (i) { case 0: //Left, sorry for hardcode cableManager.Remove(tile.gridPosition, 2); break; case 1: //Down cableManager.Remove(tile.gridPosition, 3); break; case 2: //Right cableManager.Remove(tile.gridPosition, 0); break; case 3: //Up cableManager.Remove(tile.gridPosition, 1); break; } } } } else { switch (direction) { case 0: //Left, sorry for hardcode if (leftConnection != null) { Destroy(leftConnection); } break; case 1: //Down if (downConnection != null) { Destroy(downConnection); } break; case 2: //Right if (rightConnection != null) { Destroy(rightConnection); } break; case 3: //Up if (upConnection != null) { Destroy(upConnection); } break; } } }
void Update() { if (gameObject.transform.position.y > 11) { gameObject.transform.position = new Vector3(gameObject.transform.position.x, 11, gameObject.transform.position.z); } if (powerLevel < 0) { Debug.Log("Reloading"); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } if (canMove) { //CoolDown Between each shot fired from tank (reloadTime) attackCoolDown = --attackCoolDown >= 0 ? attackCoolDown : 0; //Stat used later for calculate the total energy wasted on moving (for GUI use) double movementSubtract; //The maximum power the tank can use per update (frame) maxPowerUsage = 5; //Movement //Rotates the bottom of the tank float rot = (Input.GetAxis("Horizontal") * rotSpeed) * Time.deltaTime; player.transform.Rotate(0, rot, 0); //Moves the Tank float speed = (Input.GetAxis("Vertical") * moveSpeed) * Time.deltaTime; player.transform.Translate(0, 0, speed); //Rotates the Cannon ontop of the Tank float cannon = Input.GetKey("q") ? -1 * cannonRot * Time.deltaTime : Input.GetKey("e") ? 1 * cannonRot * Time.deltaTime : 0f; top.transform.Rotate(0, cannon, 0); //Simple equation to calcuate energy Usage from moving ( change values) movementSubtract = (Mathf.Abs(rot) + Mathf.Abs(speed) + Mathf.Abs(cannon)) / 10; //Fire if space or left mouse is clicked and the attackCoolDown is 0 if (Input.GetKey("space") && attackCoolDown == 0 || Input.GetButton("Fire1") && attackCoolDown == 0) { //checks if it has power left in its maximumpower reserve to shoot if (maxPowerUsage - selectedAbilities[1] > 0) { shoot(); //subtracts the number at selected[1] from maximumPowerUsage maxPowerUsage -= selectedAbilities[1]; } else { //sets the cannon to the lead poweful if there was not enough maximumPower selectedAbilities[1] = 1; shoot(); } } if (Input.GetKeyDown("r")) { CableManager cable = GameObject.Find("LevelManager").GetComponent <CableManager>(); if (Vector3.Distance(player.transform.position, cable.getLastCircle().transform.position) < 5) { cable.endPos = cable.endPos == player.transform ? this.transform : player.transform; } } maxPowerUsage -= movementSubtract; //The next foor loop checks if the any of the numbers on the numbpad were clicked, if so they either add a powerlevel to the selected ability or resets it to 0 if its greater than 3 if (Input.GetKeyDown("1")) { selectedAbilities[1] = selectedAbilities[1] + 1 <= 3 ? selectedAbilities[1] + 1 : 1; } if (Input.GetKeyDown("2")) { selectedAbilities[2] = selectedAbilities[2] + 1 <= 3 ? selectedAbilities[2] + 1 : 0; } if (Input.GetKeyDown("3")) { selectedAbilities[3] = selectedAbilities[3] + 1 <= 2 ? selectedAbilities[3] + 1 : 1; } if (Input.GetKeyDown("4")) { selectedAbilities[4] = selectedAbilities[4] + 1 <= 1 ? selectedAbilities[4] + 1 : 0; } //lifeSupport //checks is maxpower can hold selected[3] powerlevel *.8 if (maxPowerUsage - selectedAbilities[3] * .8 > 0) { maxPowerUsage -= selectedAbilities[3] * .8; } else { //if not selectedAbilities[4] gets reset to 0 selectedAbilities[3] = 0; } //the whole point of lifesupport is to keep a player alive, this is a simple alorgithmn to see if player loses health playerHealth = (75 / tankHealth) > selectedAbilities[3] ? playerHealth - 1 * Time.deltaTime: playerHealth; //Shield //checks is maxpower can hold selected[2] powerlevel *.7 if (maxPowerUsage - selectedAbilities[2] * .7 > 0) { //if can hold the power, change the transparency of the shield surroundign the tank based on powerlevel maxPowerUsage -= selectedAbilities[2] * .7; Color color = shield.color; color.a = selectedAbilities[2] * .09f; shield.color = color; } else { //if not set the shield to 0 selectedAbilities[2] = 0; } //light if (maxPowerUsage - selectedAbilities[4] * .5 > 0) { if (Input.GetKeyUp(KeyCode.Alpha4)) { lightActive = (lightActive) ? false : true; if (lightActive) { maxPowerUsage -= selectedAbilities[4] * .5; flashlight.SetActive(true); } if (!lightActive) { flashlight.SetActive(false); } } } else { selectedAbilities[4] = 0; flashlight.SetActive(false); } if (lightActive) { maxPowerUsage -= selectedAbilities[4] * .5; flashlight.SetActive(true); } //subtrracts the maximumpowerused from the total power powerLevel -= (5 - maxPowerUsage) * Time.deltaTime; } }