-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHitstop.cs
More file actions
43 lines (34 loc) · 1.04 KB
/
Hitstop.cs
File metadata and controls
43 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using UnityEngine;
using System.Collections;
public class Hitstop : MonoBehaviour {
public static Hitstop instance;
static Animator playerAnimator;
static Coroutine currentHitstopRoutine;
static bool currentPriority;
void Awake() {
if (instance == null) instance = this;
}
void Start() {
playerAnimator = GlobalController.pc.GetComponent<Animator>();
}
public static void Run(float seconds, bool priority=false) {
if (currentPriority && !priority) return;
Interrupt();
currentPriority = priority;
Time.timeScale = 0.01f;
playerAnimator.speed = 0;
currentHitstopRoutine = instance.StartCoroutine(EndHitstop(seconds));
}
static IEnumerator EndHitstop(float seconds) {
yield return new WaitForSecondsRealtime(seconds);
currentPriority = false;
playerAnimator.speed = 1f;
Time.timeScale = 1f;
}
public static void Interrupt() {
if (currentHitstopRoutine != null) instance.StopCoroutine(currentHitstopRoutine);
if (playerAnimator != null) playerAnimator.speed = 1f;
Time.timeScale = 1f;
currentPriority = false;
}
}