Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PauseAnimation : MonoBehaviour
- {
- private Animator _anim;
- private bool holdingJump = false;
- private void Awake()
- {
- _anim = GetComponent<Animator>();
- }
- void Update()
- {
- if (Input.GetButton("Jump"))
- holdingJump = true;
- else if (Input.GetButtonUp("Jump"))
- {
- holdingJump = false;
- ResumeAnimation();
- }
- }
- // Called from Jump animation event
- public void OnPauseWhileHoldingJump()
- {
- // When we hit the event trigger in the animation, do we pause?
- if (holdingJump)
- StopAnimation();
- }
- void StopAnimation()
- {
- _anim.speed = 0f;
- }
- void ResumeAnimation()
- {
- _anim.speed = 1f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment