[HELP] How to lock input key?
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.
Answer by Larry-Dietz · Dec 13, 2019 at 03:36 PM
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
Your answer
 
             Follow this Question
Related Questions
how do i Find an Object in the same hierarchy? 0 Answers
Position of LineRenderer end. 0 Answers
scripting problems please help 0 Answers
[Command] not called on the server 0 Answers
How do I make a script wait X time? 1 Answer