Hello, I’m a beginner in scripting
What I want is to make an action who works when I press E+ a direction, and multiply the speed of my character controller but for 0.5 seconds, and I need to wait 0.5 seconds to remake the action! I think it’s simple but I’m a noob, how do I write it?
Ask me if you need my code
Whenever the action is performed, set a variable to be the amount of delay time (0.5f in this case). Then in the update function, every frame, if it’s greater than 0, subtract deltaTime.
If you go to make the action again, check said variable, if it’s greater than 0, it’s still cooling down, and you should wait.
public class SomeScript : MonoBehaviour
{
private float _coolDown;
public void DoSomeAction()
{
if(_coolDown > 0) return;
//do action
_coolDown = 0.5f; //set cooldown
}
void Update()
{
if(_coolDown > 0) _coolDown -= Time.deltaTime;
if(** do test for key presses) this.DoSomeAction();
}
}
Do what @lordofduct said. But make it a coroutine. That way you are not doing stuff in every frame of Update.