public void TakeDmg(float amount = 1, bool playSound = true) { if (canTakeDmg) { animator.SetTrigger("TakeDmg"); canTakeDmg = false; currentHeatlh -= amount; healthBar.UpdateFillAmount(currentHeatlh / startHealth); if (playSound) { SoundManager.PlaySound(SoundManager.Sound.CannonHurtSound, Random.Range(0.8f, 1.2f)); } if (currentHeatlh <= 0) { Death(); } else { StartCoroutine(FadeSprite(0.3f, 5)); } } }
void Update() { //TEST : Roberts test aim if (Input.GetButton(shootButton)) { RobertsTestAim(true); } else { RobertsTestAim(false); } if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) { UpdateLoadImage(inventory.selectedBlock); } RotateCannon(rotationSpeed + bonunsRotationSpeed); //GameObject block = inventory.selectedBlock;// blockBuilder.blockPreFab.GetComponent<BlockType>().type; nextFire += Time.deltaTime; if (!inventory.SelectedBlockIsInInventory()) { if (Input.GetButtonDown(shootButton)) { SoundManager.PlaySound(SoundManager.Sound.CannonOutOfAmmo); } loadBar.UpdateFillAmount(0); OutOfBlocks(); return; } loadBar.UpdateFillAmount(nextFire / time); //holdCharge if (Input.GetButton(shootButton) && nextFire > time) { //Test Robban aim.Enable(); animator.SetBool("Shooting", true); holdTimer += Time.deltaTime; if (chargeIsntStarted) { startPos = transform.position; } if (holdTimer > 0.3f) { ChargeCannon(); chargeIsntStarted = false; } } //Shoot if (Input.GetButtonUp(shootButton) && nextFire > time) { holdTimer = 0; time = fireRate; nextFire = 0; if (Time.timeScale != 0) { ShootBlock(chargePower); GameObject particleEffekt = Instantiate(shootEffekt, shootPos.position - (shootPos.right * 0.5f), shootPos.rotation * Quaternion.Euler(0, particleRotation, 0)); } chargePower = 1; transform.localScale = normalScale; chargeIsntStarted = true; animator.SetBool("Shooting", false); } }