C# Hi guys… I’m kinda new to unity, how to make multiple animation with just 1 button? for example, if I press F button the character do an attack animation and if I press F twice the character do next animation of attack, its like 1 button with combo attack
I haven’t tested, but you can try something like this :
// C#
public class MyCharacter: MonoBehaviour
{
public float comboDelay = 1 ; // You have 1 second to press the button to do a combo
private Animator animator; // Animator component
private float timer = 0 ; // Timer to compare with the combo delay
void Start ()
{
animator = GetComponent<Animator>();
}
void Update ()
{
if( timer > 0 )
timer += Time.deltaTime ;
// Do not allow combo if the user waited to long
if( timer > comboDelay )
timer = 0 ;
if( Input.GetKeyDown(KeyCode.F) )
{
// Simple attack
if( timer == 0 )
{
animator.SetTrigger("Attack");
timer += Time.deltaTime ;
}
// Test if user can do a combo attack
else if( timer <= comboDelay )
{
animator.SetTrigger("Combo");
// reset timer to come back to simple attack
timer = 0 ;
}
}
}
}