Need a key input delay,need an input delay
void Update() {
position.x += Input.GetAxis ("Horizontal") * carSpeed * Time.deltaTime;
position.x = Mathf.Clamp (position.x, -2.3f, 2.3f);
transform.position = position;
},
Comment
Best Answer
Answer by SpasticDad · Dec 28, 2018 at 04:19 PM
Basically you want to check if a certain time has passed since the key was pressed, and then execute an action right?
this should do that:
public float MaxTime;
private float timer;
private void Update()
{
if (Input.GetAxisRaw("Horizontal") != 0)
{
if (timer > MaxTime)
{
//do the stuff here
}
else
{
timer += Time.deltaTime;
}
}
else
{
timer = 0;
}
}
keep in mind that this is just a quick solution and not well optimized. You should look into coroutines for that.
Your answer
Follow this Question
Related Questions
Having an issue with touch input lag on certain Android devices, any help? 1 Answer
GetKeyUp does not get called sometimes. 1 Answer
using a button witout pressing it ? 1 Answer
This is weird - Assembly hi could not be loaded 1 Answer
How do i make up and down button script for Mobile in Unity 5.3.2 0 Answers