@IrOn_KiT Well when you say shorten, I assume you also mean more readable. I’ve been experimenting using Pattern Matching with Switch Statements as an alternative to the classic If-Else statements and I went ahead and added some comments to my code and took the liberty of adding a few variables and features. This is probably how I would do it, but feel free to experiment and add your own twist.
public bool IsJabbing { get; protected set; }
public int Jabs { get; protected set; }
[SerializeField]
private GameObject jabHitbox;
[Tooltip("The amount of frames a jab lasts.")]
[SerializeField]
private int maxJabs = 10;
private void Update()
{
// Checks that the jabHitbox has been assigned
if (jabHitbox)
switch (IsJabbing)
{
// The first frame when you are not jabbing and jab button is pressed
case false when Input.GetKeyDown(KeyCode.P):
IsJabbing = true;
Jabs = 0;
jabHitbox.SetActive(true);
break;
// When you are jabbing and hit the maximum amount of frames for jabbing
case true when Jabs > maxJabs:
jabHitbox.SetActive(false);
IsJabbing = false;
break;
// When you are otherwise jabbing
case true:
Jabs++;
break;
}
}