private void SwordAttack() { if (hasSword && Input.GetKeyDown(KeyCode.LeftShift) && swordTimer == 0.2f) { PlayASound(SwordSwingClip, ChangeVolume.soundVolume); sword.SetActive(false); SwordWhileSwinging.SetActive(true); startSwordTimer = true; if (swordTimer <= 0) { sword.SetActive(true); SwordWhileSwinging.SetActive(false); swordTimer = 0.2f; } } if (startSwordTimer) { swordTimer -= Time.deltaTime; } if (swordTimer <= 0) { sword.SetActive(true); SwordWhileSwinging.SetActive(false); startSwordTimer = false; swordTimer = 0.2f; } }
private void SwordAttack() { if (hasSword && Input.GetKeyDown(KeyCode.E)) { sword.SetActive(false); SwordWhileSwinging.SetActive(true); } else if (hasSword && Input.GetKeyUp(KeyCode.E)) { sword.SetActive(true); SwordWhileSwinging.SetActive(false); } }
//if player colldes with ground set animator bool and script bool to true. private void OnCollisionEnter2D(Collision2D c) { if (c.gameObject.tag == "SwordAttackPowerUp") { //I am still working on the Swords function. //GameObject swordWeapon = Instantiate(sword, shotSpawn.position, Quaternion.identity); hasSword = true; hasLaserGun = false; sword.SetActive(true); LaserGun.SetActive(false); Destroy(c.gameObject); } if (c.gameObject.tag == "LaserGun") { Destroy(c.gameObject); hasSword = false; hasLaserGun = true; LaserGun.SetActive(true); sword.SetActive(false); SwordWhileSwinging.SetActive(false); //Instantiate(LaserGun, shotSpawn.position, shotSpawn.rotation); } if (c.gameObject.tag == "Armour" && ArmourBar.armourAmount < 3) { ArmourBar.armourAmount = ArmourBar.armourAmount + 1; Destroy(c.gameObject); } if (c.gameObject.tag == "Ground") { onGround = true; anim.SetBool("onGround", true); } //loads gameOver scene when the player dies. if (c.gameObject.tag == "Enemy" || c.gameObject.tag == "EProjectile") { //EnemyFlyingDrones are listed as a projectile meaning they and other projectiles will be //destroyed when they touch the player if (c.gameObject.tag == "EProjectile") { Destroy(c.gameObject); } //NOTE MUST ADD TEMP INVINCIBILITY if (!hasArmour) { Health.life--; } else if (hasArmour) { ArmourBar.armourAmount--; } } if (c.gameObject.tag == "CherryPowerUp") { speed = speed + 5; Destroy(c.gameObject); } if (c.gameObject.tag == "InvisiblePotion") { playerSpriteRenderer.color = new Color(1f, 1f, 1f, 0.5f); isInvisable = true; Destroy(c.gameObject); StartCoroutine(waitAndTurnOffInvisibility()); } //sets the firepower attack bool true. if (c.gameObject.tag == "StrawBerry") { firePower = true; } if (c.gameObject.tag == "Pie") { Health.life++; Destroy(c.gameObject); } }
//if player colldes with ground set animator bool and script bool to true. private void OnCollisionEnter2D(Collision2D c) { if (c.gameObject.tag == "SwordAttackPowerUp") { hasSword = true; hasLaserGun = false; sword.SetActive(true); LaserGun.SetActive(false); Destroy(c.gameObject); PlayASound(gotPowerUpClip, ChangeVolume.soundVolume); } if (c.gameObject.tag == "Ground") { onGround = true; anim.SetBool("onGround", true); } if (c.gameObject.CompareTag("MovingPlatform")) { Debug.Log("on platform"); onGround = true; anim.SetBool("onGround", true); myTransform.parent = c.gameObject.transform; } if (c.gameObject.tag == "LaserGun") { Destroy(c.gameObject); hasSword = false; hasLaserGun = true; LaserGun.SetActive(true); sword.SetActive(false); SwordWhileSwinging.SetActive(false); PlayASound(gotPowerUpClip, ChangeVolume.soundVolume); //Instantiate(LaserGun, shotSpawn.position, shotSpawn.rotation); } if (c.gameObject.tag == "Armour") { if (ArmourBar.armourAmount <= 3) { ArmourBar.armourAmount = ArmourBar.armourAmount + 1; } Destroy(c.gameObject); PlayASound(gotPowerUpClip, ChangeVolume.soundVolume); } if (!isInvinsable && (c.gameObject.CompareTag("Enemy") || c.gameObject.CompareTag("EProjectile"))) { //starts the coroutine that makes the player invinsible StartCoroutine(TempInvinsibility()); //projectiles will be destroyed when they touch the player if (c.gameObject.tag == "EProjectile") { Destroy(c.gameObject); } if (c.gameObject.CompareTag("Enemy")) { anim.SetBool("onGround", true); } if (!hasArmour) { Health.life--; } else if (hasArmour) { ArmourBar.armourAmount--; } } if (c.gameObject.tag == "Blockman") { startCountdownTillDeath = true; rb.velocity = new Vector3(0, 0, 0); myTransform.localScale = new Vector3(myTransform.localScale.x, 3.5f, myTransform.localScale.z); anim.enabled = false; } if (c.gameObject.tag == "CherryPowerUp") { speed = speed + 2; Destroy(c.gameObject); PlayASound(gotPowerUpClip, ChangeVolume.soundVolume); } if (c.gameObject.tag == "Invincible") { playerSpriteRenderer.color = new Color(1f, 1f, 1f, 0.5f); isInvinsable = true; PlayASound(gotPowerUpClip, ChangeVolume.soundVolume); Destroy(c.gameObject); StartCoroutine(waitAndTurnOffInvinsibility()); } if (c.gameObject.tag == "Gem") { Gem gem = c.gameObject.GetComponent <Gem>(); if (gem) { points += gem.Points; Destroy(c.gameObject); PlayASound(gemPickUpClip, ChangeVolume.soundVolume); } } }