/// <summary> /// Called periodically. Handles the dash mechanic, setting the target, and more. /// </summary> public void Update() { // Stores the player's velocity when the level is paused if (LevelController.Singleton.Paused && oldVelocity == Vector3.zero) { oldVelocity = GetComponent <Rigidbody2D>().velocity; GetComponent <Rigidbody2D>().velocity = Vector3.zero; // Cancel dash targeting on pause selecting = false; SetMoveTarget(field.WorldPoint(mousePos)); dashRenderer.enabled = false; } else if (!LevelController.Singleton.Paused && oldVelocity != Vector3.zero) { GetComponent <Rigidbody2D>().velocity = oldVelocity; oldVelocity = Vector3.zero; } if (!LevelController.Singleton.Paused) { HandleInput(); // General movement-related functions if (moving) { targetRenderer.enabled = true; moving = Vector2.Distance(transform.position, target) > (dashing ? 1 : 0.1); if (!moving) { // Player reached its target targetRenderer.enabled = false; dashing = false; rigidbody2d.velocity = Vector3.zero; } } else if (selecting) { targetRenderer.enabled = true; } // Handling the dash cooldown if (dashes < maxDashes) { dashCooldown += Time.deltaTime; if (dashCooldown >= MAX_DASH_COOLDOWN) { dashes++; dashCooldown = 0; dashRenderer.SetColors(dashStartActive, dashEndActive); dashCounter.UpdateCounter(dashes); } } } }