using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float runSpeed = 20;
public float standartSpeed = 10;
public float staminaValue = 5;
public float currentSpeed = 10;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
Stamina();
currentSpeed = standartSpeed;
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
rb.velocity = new Vector2(currentSpeed * x, currentSpeed * y);
}
private void Stamina()
{
if (Input.GetKey(KeyCode.LeftShift) && staminaValue > 0)
{
staminaValue -= Time.deltaTime;
currentSpeed = runSpeed;
}
if (!(Input.GetKeyUp(KeyCode.LeftShift) && staminaValue > 0))
{
staminaValue += Time.deltaTime;
currentSpeed = standartSpeed;
}
}
}