private void Update() { //todo gameover if (health.value <= 0) { gameover.SetActive(true); } //mana regained after cooldown timeLeft -= Time.deltaTime; if (timeLeft < 0) { health.value++; timeLeft = coolDown; } movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (Input.GetMouseButtonDown(1)) { old_vector = new Vector2(-2, -2); spellChain = ""; } else if (Input.GetMouseButton(1)) { animator.SetBool("Spell", true); animator.SetFloat("input_x", movement_vector.x); animator.SetFloat("input_y", movement_vector.y); if (movement_vector != old_vector) { if (movement_vector == new Vector2(1, 0)) { spellChain += "R"; } else if (movement_vector == new Vector2(-1, 0)) { spellChain += "L"; } else if (movement_vector == new Vector2(0, 1)) { spellChain += "U"; } else if (movement_vector == new Vector2(0, -1)) { spellChain += "D"; } old_vector = movement_vector; } Debug.Log("spell " + spellChain); movement_vector = Vector2.zero; } else if (Input.GetMouseButtonUp(1)) { spellCheck(spellChain); prevDir = new Vector2(0, -1); } else { animator.SetBool("Spell", false); if (movement_vector != Vector2.zero) { animator.SetBool("isWalking", true); animator.SetFloat("input_x", movement_vector.x); animator.SetFloat("input_y", movement_vector.y); } else { animator.SetBool("isWalking", false); } prevDir = (movement_vector.Equals(Vector2.zero)) ? prevDir : movement_vector; if (Input.GetMouseButtonDown(0)) { switch (spellIndex) { case 0: Debug.Log("Fireball!"); if (health.value > 5) { //create tmp variable to call its function FireBall tmp = (FireBall)Instantiate(fireball, new Vector3(transform.position.x + 0.8f + prevDir.x * 2f, transform.position.y + 1 + prevDir.y * 2f, transform.position.z), Quaternion.identity); //send normalized vector to our created fireball tmp.Dir(prevDir.normalized); health.value -= 5; } break; case 1: Debug.Log("Soul given!"); if (health.value > 10) { SoulBall tmpS = (SoulBall)Instantiate(soulball, new Vector3(transform.position.x + 0.8f + prevDir.x * 2f, transform.position.y + 1 + prevDir.y * 2f, transform.position.z), Quaternion.identity); //send normalized vector to our created fireball tmpS.Dir(prevDir.normalized); health.value -= 10; } break; default: Debug.Log("No active spell"); break; } } } rbody.MovePosition(rbody.position + movement_vector / 10); }