This question was
closed Jun 20, 2016 at 10:07 AM by
Vergil27.
How to make more combo attack,,
Need help, i want to make combo attack, but it just 2 attacking, but i need 4 attacking. this my script :
if (Input.GetButtonDown("Fire1")) {
if (!fired) {
fired = true;
timer = 0.0f;
comboCount = 0.0f;
animator.SetBool("Attack1", true); //this my attack1
Debug.Log("I served a punch!");
} else
{
comboCount++;
if (comboCount == comboNum)
{
animatio.SetBool("Attack2", true); //this my attack2, but i need more,,
Debug.Log("I did a combo!");
}
// how i can to add more animation for attack, i need to make 2 more attack
}
}
if (fired)
{
timer += Time.deltaTime;
if (timer > fireRate)
{
fired = false;
}
}
Comment
Best Answer
Answer by Hellium · May 27, 2016 at 11:40 AM
Here is a solution that will work. I think triggers will be more appropriate for your case. Take a look at the animator I created :
public float fireRate = 2;
public string[] comboParams ;
private int comboIndex = 0 ;
private Animator animator;
private float resetTimer;
void Awake()
{
if( comboParams == null || (comboParams != null && comboParams.length == 0)
comboParams = new string[]{ "Attack1", "Attack2", "Attack3", "Attack4" };
animator = GetComponent<Animator>() ;
}
void Update()
{
if ( Input.GetButtonDown( "Fire1" ) && comboIndex < comboParams.Length )
{
Debug.Log( comboParams[comboIndex] + " triggered" );
animator.SetTrigger( comboParams[comboIndex] );
// If combo must not loop
comboIndex++;
// If combo can loop
// comboIndex = (comboIndex + 1) % comboParams.Length ;
resetTimer = 0f;
}
// Reset combo if the user has not clicked quickly enough
if ( comboIndex > 0 )
{
resetTimer += Time.deltaTime;
if ( resetTimer > fireRate )
{
animator.SetTrigger( "Reset" );
comboIndex = 0;
}
}
}
animator.jpg
(88.7 kB)
the problem is : animationBools = new string[]{"Attack1", etc} the word of string is wrong, how i can fix it ??
Try with this syntax :
animationBools = { "Attack1", "Attack2", "Attack3", "Attack4" } ;
@Vergil27 Answer edited again, and successfully tested ;)
i have a problem to error CS1525: Unexpected symbol `comboParams'. why this happen?