Search Unity

Question Attack Animation Freezing Every Other Animation

Discussion in 'Animation' started by Noahhjnz, Nov 1, 2022.

  1. Noahhjnz

    Noahhjnz

    Joined:
    Sep 14, 2022
    Posts:
    4
    I'm trying to set up an attack animation for my game, just a small school project. I've never used unity and I'm not super familiar with it.

    I've been following this video as a guide

    However, i've found that when I have the transition for my attack animation from any state it freezes everything but when removed it works fine.
    - video showing my issue.

    here is my player combat script, if it helps.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class playercombat : MonoBehaviour
    4. {
    5.     public Animator anim;
    6.     public Transform attackpoint;
    7.     public float attackrange = 0.5f;
    8.     public LayerMask enemyLayers;
    9.  
    10.     // Update is called once per frame
    11.     void Update()
    12.     {
    13.         if (Input.GetKeyDown(KeyCode.Space));
    14.         {
    15.             attack();
    16.         }
    17.     }
    18.  
    19.     void attack()
    20.     {
    21.         //play atk animation
    22.         anim.SetTrigger("attack");
    23.         // dectect enimies in range
    24.         Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackpoint.position, attackrange, enemyLayers);
    25.         //apply damage
    26.         foreach(Collider2D enemy in hitEnemies)
    27.         {
    28.             Debug.Log("Hit" + enemy.name);
    29.         }
    30.     }
    31. }
    32.