So i want to create a Stamina System in wich after 1-2 seconds of running the stamina bar gets to 0 and then it regenerates in like 5 seconds (And btw if someone could help me to make my running script not be toggleable i would apreciate it, i want to press shift and run while shift is pressed, rn when i press shift it starts running until you press shift again, thanks in advance <3), here’s my code:
using UnityEngine;
public class MovimientoJugador : MonoBehaviour
{
public float speed;
public Rigidbody2D rb;
private Vector2 moveVelocity;
public float runningspeed;
// Update is called once per frame
void Update()
{
Vector2 moveimput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveimput.normalized * speed;
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
if (Input.GetKey(KeyCode.LeftShift))
{
rb.MovePosition(rb.position + moveVelocity * runningspeed * Time.fixedDeltaTime); ;
}
}
}