Search Unity

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:
    191
    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:
    191
    Yes sir