Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

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.