void CastSpell(GameObject prefab, ref float timer, float cooldown, bool unlocked, string trigger, CoolDownTimer icon) { if (Time.time > timer && unlocked) { timer = Time.time + cooldown; var spell = Instantiate(prefab).GetComponent <Ability>(); spell.Init(this); animator.SetTrigger(trigger); icon.Spin(cooldown); } }
// Update is called once per frame void Update() { if (!gameOver) { if (transform.position.y < bottomOfWorld) { gameOver = true; gameOverText.text = "Game Over\n Press Space to retry level or Esc to return to menu\n Souls Collected:" + soulCount.ToString(); } setHealthBar(); if (Health < 0f && !playerDead) { //Destroy(gameObject); animator.SetTrigger("playerDead"); playerDead = true; gameOver = true; gameOverText.text = "Game Over\n Press Space to retry level or Esc to return to menu\n Souls Collected:" + soulCount.ToString(); } if (Mobile) { // The player is grounded if a linecast to the groundcheck position hits anything on the ground layer. //grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground")); // If the jump button is pressed and the player is grounded then the player should jump. if (Input.GetButtonDown("Jump") && (grounded || wallState != WallStatuses.OffWall)) { jump = true; animator.SetTrigger(jumping); } // melee if (Input.GetButtonDown("Melee")) { CastSpell(MeleeAttack, ref meleeTimer, meleeCoolDown, true, meleeing, Qicon); } // projectile if (Input.GetButtonDown("Fire1") && rangedUnlocked) { CastSpell(Projectile, ref projectileTimer, projectileCoolDown, rangedUnlocked, throwing, rangedIcon); } else if (Input.GetButtonDown("Fire1") && dashUnlocked && Time.time >= dashTimer) { dashIcon.Spin(dashCoolDown); dash = true; animator.SetTrigger(running); dashTimer = Time.time + dashCoolDown; } // siphon if (Input.GetButtonDown("Fire2") && grounded && siphonUnlocked) { CastSpell(siphon, ref siphonTimer, siphonCoolDown, siphonUnlocked, idling, siphonIcon); } else if (Input.GetButtonDown("Fire2") && silenceUnlocked) { CastSpell(SilenceAlert, ref silenceTimer, silenceCoolDown, silenceUnlocked, throwing, lightsOutIcon); } // hand if (Input.GetButtonDown("Fire3") && zombieHandsUnlocked) { CastSpell(ZombieHands, ref handTimer, handCoolDown, zombieHandsUnlocked, throwing, handIcon); } else if (Input.GetButtonDown("Fire3") && chokeHoldUnlocked) { CastSpell(ChokeHold, ref chokeHoldTimer, chokeHoldCoolDown, chokeHoldUnlocked, meleeing, KOIcon); } //// dash //if (Input.GetButtonDown("Dash") && dashUnlocked) //{ // dash = true; // animator.SetTrigger(running); //} //// silence //if (Input.GetButtonDown("Silence")) //{ // CastSpell(SilenceAlert, ref silenceTimer, silenceCoolDown, silenceUnlocked, throwing); //} //// choke hold //if (Input.GetButtonDown("ChokeHold")) //{ // CastSpell(ChokeHold, ref chokeHoldTimer, chokeHoldCoolDown, chokeHoldUnlocked, meleeing); //} var hit = Physics2D.Raycast(transform.position, -transform.up, 1f, 1 << LayerMask.NameToLayer("Ground")); Debug.DrawRay(transform.position, -transform.up, Color.green); if ((wallState != WallStatuses.OffWall) && hit && hit.collider.tag == "Wall") { grounded = true; wallState = WallStatuses.OffWall; } } } else if (gameOver) { if (Input.GetKeyDown(KeyCode.Space)) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); soulCount = 0; } if (Input.GetKeyDown(KeyCode.Escape)) { SceneManager.LoadScene("Title_Screen"); } } else if (!playerDead) { animator.SetTrigger("playerIdle"); } }