Search Unity

Assets Enigma Project Keyboard Animation

Discussion in 'Works In Progress - Archive' started by dimichelec, Nov 29, 2019.

  1. dimichelec

    dimichelec

    Joined:
    Sep 19, 2017
    Posts:
    2
    The keyboard animation is coming along on this project. I play a key's 'Pressing' animation on a KeyDown event then trigger playing the same animation in reverse on the KeyUp event. The Enigma's 'compensator' part (the pivoted see-saw bar beneath the keys) responds to any key press. On a key press, iff a 'keydown' Boolean parameter is not true, the script plays the compensator's 'Pressing' animation and sets the 'keydown' flag.

    When all keys are up, the script clears the 'keydown' flag triggering playing the compensator 'Pressing' animation in reverse. Every once in a while, I can get a key to stick midway in it's 'Pressing' animation. Any ideas on where to look for the root cause would be appreciated.

    Code (CSharp):
    1.  
    2.     void Update()
    3.     {
    4.         if (Input.GetKeyDown(key))
    5.         {
    6.             animator.Play("Pressing");
    7.             if (!compAnimator.GetBool("keydown"))
    8.             {
    9.                 compAnimator.Play("Pressing");
    10.                 compAnimator.SetBool("keydown", true);
    11.             }
    12.         }
    13.         else if (Input.GetKeyUp(key))
    14.         {
    15.             animator.SetTrigger("unpress");
    16.         }
    17.  
    18.         if (!Input.anyKey)
    19.         {
    20.             compAnimator.SetBool("keydown", false);
    21.         }
    22.     }
    23.  
    enigma_button_animation.png
     
    Last edited: Nov 29, 2019