Search Unity

Question Script failing to play animation

Discussion in 'Animation' started by CjScout, May 4, 2022.

  1. CjScout

    CjScout

    Joined:
    Jul 15, 2020
    Posts:
    1
    Hello,

    I'm trying to animate an object. It should, when a button on my controller is pressed, play said animation. When I press the button for
    DecreaseChannel
    it sends
    Animate!
    to the console, however, the animation does not run. I have also attached a screenshot of the animated object's properties.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class WaveD : MonoBehaviour
    7. {
    8.     PlayerControls controls;
    9.     private Animator animate;
    10.  
    11.     void Start()
    12.     {
    13.         animate = GetComponent<Animator>();
    14.     }
    15.  
    16.     void Awake()
    17.     {
    18.         controls = new PlayerControls();
    19.  
    20.         controls.Gameplay.DecreaseChannel.performed += ctx => playAnim();
    21.  
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.      
    28.     }
    29.  
    30.     void playAnim()
    31.     {
    32.         Debug.Log("Animate!");
    33.         animate.Play("Waves");
    34.     }
    35.  
    36.     void OnEnable()
    37.     {
    38.         controls.Gameplay.Enable();
    39.     }
    40.  
    41.     void OnDisable()
    42.     {
    43.         controls.Gameplay.Disable();
    44.     }
    45. }
    46.  
     

    Attached Files:

    Last edited: May 4, 2022