eastbayeff

Untitled

May 24th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PauseAnimation : MonoBehaviour
  6. {
  7.     private Animator _anim;
  8.     private bool holdingJump = false;
  9.  
  10.     private void Awake()
  11.     {
  12.         _anim = GetComponent<Animator>();
  13.     }
  14.  
  15.     void Update()
  16.     {
  17.         if (Input.GetButton("Jump"))
  18.             holdingJump = true;
  19.  
  20.         else if (Input.GetButtonUp("Jump"))
  21.         {
  22.             holdingJump = false;
  23.             ResumeAnimation();
  24.         }      
  25.     }
  26.  
  27.     // Called from Jump animation event
  28.     public void OnPauseWhileHoldingJump()
  29.     {
  30.         // When we hit the event trigger in the animation, do we pause?
  31.         if (holdingJump)
  32.             StopAnimation();    
  33.     }
  34.  
  35.     void StopAnimation()
  36.     {
  37.         _anim.speed = 0f;
  38.     }
  39.  
  40.     void ResumeAnimation()
  41.     {
  42.         _anim.speed = 1f;
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment