Making a skill basics on stamina mechanics. When i hold shift for example, skill works and bar getting smaller, but how to lock input key? When i press shift and not holding, skill work and when i press again it stops. please help. Script below.
First off, when putting code in a question, use the “101/010” button and put the code in as text instead of a picture. It helps people show you modifications to make without them having to retype your existing code into the answer.
To answer your question. I would create a boolean variable, and toggle it each time the LeftShift key is pressed, and use this variable in your if statements. Something like this…
bool UseSkill = false;
void Update()
{
if(Input.GetKeyDown(KeyCode.LeftShift))
UseSkill = !UseSkill;
if(UseSkill && currentGhostPoints > 0)
{
currentGhostPoints -=100 * Time.deltaTime;
}
RegenGhostPoints();
}
void RegenGhostPoints()
{
if(!useSkill && currentGhostPoints < 100)
{
currentGhostPoints += 10 * Time.deltaTime;
}
}
Just typed this directly into the answer, so no guarantee against typos
Hope this help,
-Larry