My player can do attack while moving but the animation is not playing. So, what I want is, when the Attack Button is pressed, then the player will be stopped and the animation play. How to do that ?
void Move()
{
if (isAttacking) return;
// movement code
}
void Attack()
{
isAttacking = true;
// attacking code.
}
Just return conditionally in the movement code. It’s hard to be more specific than that unless you post some code and give more context.
This is my movement and attack script…
void Update () {
dirX = CrossPlatformInputManager.GetAxis ("Horizontal");
if (CrossPlatformInputManager.GetButtonDown ("Fire1") && comboIndex < comboParams.Length) {
rb.velocity = Vector2.zero;
Debug.Log (comboParams [comboIndex] + " triggered");
attackArea [comboIndex].enabled = true;
anim.SetTrigger (comboParams [comboIndex]);
comboIndex++;
resetTimer = 1.6f;
//Physics2D.IgnoreLayerCollision (collidableEnemyLayer, playerLayer, false);
}
if (comboIndex > 0) {
resetTimer += Time.deltaTime;
if (resetTimer > fireRate) {
attackArea [0].enabled = false;
attackArea [1].enabled = false;
attackArea [2].enabled = false;
anim.SetTrigger ("Reset");
comboIndex = 0;
}
}
void FixedUpdate()
{
rb.velocity = new Vector2 (dirX * moveSpeed, rb.velocity.y);
}