Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Play animation until i stop pressing it

Discussion in 'Visual Scripting' started by aaronghosh14A, Sep 14, 2020.

  1. aaronghosh14A

    aaronghosh14A

    Joined:
    Nov 9, 2019
    Posts:
    13
    Hello everyone , i want to make that when i have pressing the button the walk animation should loop but when i press it , it plays for 3 sec then stops .
    Can anybody help me how to play a animation until i stop pressing it .
     
    michealcaj likes this.
  2. michealcaj

    michealcaj

    Joined:
    Aug 18, 2017
    Posts:
    177
    Code (CSharp):
    1.  
    2. Float delaytime;
    3. void FixedUpdate ()
    4. {
    5.   Float V = input.Getaxis("Vertical");
    6.   delaytime = V > 0 ? 3 : delaytime;
    7.  
    8.   If(V == 0)
    9.   {
    10.    If (delaytime > 0.1f)
    11.   delaytime -= Time.deltatime;
    12.    else if(delaytime < 0.1f)
    13.   delaytime = 0.0f;
    14.   }
    15. //
    16.   anim.setfloat("walk", delaytime);
    17. }
     
  3. Ex-Crow

    Ex-Crow

    Joined:
    Aug 14, 2020
    Posts:
    111
    Visual Scripting forum category is for Bolt visual scripting which is the official Unity visual scripting system and it's mainly aimed at non-programmers so suggesting C# solutions is a bit counter-productive.
     
  4. michealcaj

    michealcaj

    Joined:
    Aug 18, 2017
    Posts:
    177
    Yes sir
     
unityunity