- Home /
Is there a way to do different things depending on whether the button is being held or tapped?
For example I want to do a light attack when the "attack" button is tapped and do a heavy attack when the button is being held down. I tried using Input.GetButtonDown for light attack and Input.GetButton for heavy attack, but that doesn't work.
if (Input.GetButtonDown("attack"))
{
attackState = 1;
}
else if (Input.GetButton("attack"))
{
attackState = 2;
}
Answer by Vollmondum · Jul 03, 2017 at 08:24 PM
Add a boolean and a timer, specifying when to consider your attack being "Heavy".
var buttonDown: boolean;
var buttonDownTimer: float;
var heavyAttackThreshold: float;
function Update()
{
if (Input.GetButtonDown("attack"))
{
buttonDown = true;
}
if(buttonDown)
{
buttonDownTimer += Time.deltaTime;
}
if (Input.GetButtonUp("attack"))
{
buttonDown = false;
if(buttonTimer >= heavyAttackThreshold)
{
attackState = 2;
}
else
{
attackState = 1;
}
}
}
Answer by OusedGames · Jul 04, 2017 at 02:15 AM
By Script
OnMouseOver() OnMouseEnter() OnMouseDown() OnMouseUp() OnMouseDrag()
Your answer
Follow this Question
Related Questions
Input button 0 Answers
Ensuring that a button is released before checking that it's pressed? 2 Answers
How to Attack using Animation and Input 0 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Is there any function to check how long a button is pressed? 2 Answers