private void Update() { movementVector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (movementVector != Vector2.zero && !dashing) { direction = movementVector.normalized; } touchingCollisionEdge = Physics2D.OverlapBox(feetpos.position, CheckSize, 0, edge); touchingWalk = Physics2D.OverlapBox(feetpos.position, CheckSize, 0, walk); isMoving = movementVector != Vector2.zero; anim.SetBool("Running", isMoving); #region Controlling if (movementOverAngle) { anim.SetInteger("DirectionX", (int)movementVector.x); anim.SetInteger("DirectionY", (int)movementVector.y); if (movementVector.x < 0) { book.playerSpr.flipX = true; } else if (movementVector.x > 0) { book.playerSpr.flipX = false; } } if (Input.GetKeyDown(KeyCode.Space) && !stopMoving) { dashing = true; Invoke("EndDash", dashLength); } if (dashing) { rb.velocity = direction * dashForce; gameObject.layer = 13; } if (!dead && !dashing && !stopMoving) { shadows.SetActive(true); anim.enabled = true; rb.velocity = movementVector * speed; //rb.MovePosition(rb.position + ((movementVector * speed) * Time.deltaTime)); book.enabled = true; } else { book.enabled = false; anim.enabled = false; if (stopMoving) { rb.velocity = Vector2.zero; EndDash(); } } if (!touchingCollisionEdge && !touchingWalk) { shadows.SetActive(false); } if (Input.GetButtonDown("Fire1") && book.gameObject.activeSelf == true) { movementOverAngle = false; book.AngleCheck(right, left, top, bottom); Invoke("SetMovementOverAngle", 0.8f); } #endregion #region Death and Health if (health > maxHealth) { health = maxHealth; } for (int i = 0; i < hearts.Length; i++) { if (i < health) { hearts[i].sprite = fillHearts; } else { hearts[i].sprite = notFilledHearts; } if (i < maxHealth) { hearts[i].enabled = true; } else { hearts[i].enabled = false; } } for (int i = 0; i < manaContainer.Length; i++) { if (i < book.mana) { manaContainer[i].sprite = fillMana; } else { manaContainer[i].sprite = notFilledMana; } if (i < book.maxMana) { manaContainer[i].enabled = true; } else { manaContainer[i].enabled = false; } } if (currentInvincTime > 0) { currentInvincTime -= Time.deltaTime; } if (((touchingCollisionEdge && !touchingWalk) || (!touchingCollisionEdge && !touchingWalk)) && !dashing) { stopMoving = true; shadows.SetActive(false); falling = true; Invoke("Die", 0.5f); } if (health <= 0) { falling = false; Die(); } #endregion //transform.position = new Vector3(transform.position.x, transform.position.y, 0); }