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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Animation not playing upon click of the binded button.

Discussion in 'Getting Started' started by truukrikk, Apr 26, 2022.

  1. truukrikk

    truukrikk

    Joined:
    Mar 3, 2022
    Posts:
    5
    Hello

    I am new to Unity.

    I am using the new Input System and Third Person Starter Assets. I created another layer in Animator for my Attack Animation(masked it only for upper body), added one empty named "New State" and transitioned that into the punch Animation.

    From New State -> Punching / No Exit Time
    From Punching -> New State / Exit Time enabled

    I have binded my "Punching" animation to the Left Mouse Click.

    Also I created a new script, which I added to the Player.


    The mouse button does not do the Punching animation. No response.




    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using StarterAssets;
    6.  
    7. public class Animations : MonoBehaviour
    8. {
    9.     private StarterAssetsInputs starterAssetsInputs;
    10.     public Animator anim;
    11.  
    12.     private void Awake() {
    13.         starterAssetsInputs = GetComponent<StarterAssetsInputs>();
    14.         anim = GetComponent<Animator>();
    15.     }
    16.  
    17.     private void Update (){
    18.         if (starterAssetsInputs.attack)
    19.          anim.Play("Punching");
    20.      }
    21.  
    22.    
    23. }
    24.  
    25.  
    Screenshot of my Attack Layer error. I can't have Exit Time as condition on this transition, but I think that mouse click could be a condition, how should I do it, any info is helpful.




    I added a public bool named attack.


    And these are the Input Bindings
     
    Last edited: Apr 27, 2022
  2. truukrikk

    truukrikk

    Joined:
    Mar 3, 2022
    Posts:
    5
    Asking for help
     
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    If you're seeing an error, you'll want to share the actual full error here and not just the gist of what the message was saying.

    Also, just by looking at it, your script looks broken. One too many closing brackets. Keeping your code tidy and formatted correctly with proper indentation can help you spot that kind of thing.
     
  4. truukrikk

    truukrikk

    Joined:
    Mar 3, 2022
    Posts:
    5
    Okay, my bad, give me 60 minutes and Ill give you the details.

    I already fixed the closing brackets, but error seems to be still there.
     
    Last edited: Apr 27, 2022
  5. truukrikk

    truukrikk

    Joined:
    Mar 3, 2022
    Posts:
    5
    Hey, I have edited my question. Help would be appreciated. :)
     
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    I don't do a lot of animation, but I think you have to add a Parameter in your Animator. And then in your controller script, you'd have a reference to the animator and set the parameter value, which can be used to change the animation state.

    Someone with more animation experience may be able to tell you more or correct what I have wrong here. It looks like you're close, though, and are just missing one little element. Just wish I could spot it for you. :(
     
  7. truukrikk

    truukrikk

    Joined:
    Mar 3, 2022
    Posts:
    5
    Okay, I will search the net, been struggling for couple of days with it. Most of the videos that are exactly what I need are outdated as the new input system is here.

    Hopefully I find an answer as this is gonna be for my college. Appreciate it, thanks!
     
  8. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    Yeah, that's the way it goes with tutorials. You'll often have to piece together things from several different ones and resolve the issues between them. I've got a full schedule today, but if you haven't gotten it by tomorrow I'll try loading up a project where I used the new input system and had some animations to play and see if I can give you any pointers.

    Good luck!