-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParticaleAnimator.cs
More file actions
44 lines (39 loc) · 1014 Bytes
/
ParticaleAnimator.cs
File metadata and controls
44 lines (39 loc) · 1014 Bytes
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
44
using UnityEngine;
public class ParticaleAnimator : MonoBehaviour {
private ParticleSystem pSystem;
private double lastInterval;
private float deltaTime;
private bool isSimulate = false;
public void Awake() {
lastInterval = Time.realtimeSinceStartup;
pSystem = gameObject.GetComponent<ParticleSystem>();
isSimulate = pSystem.playOnAwake;
}
public void Update() {
if(!isSimulate) {
return;
}
deltaTime += Time.realtimeSinceStartup - (float)lastInterval;
lastInterval = Time.realtimeSinceStartup;
if(Time.timeScale == 0) {
if(deltaTime >= pSystem.duration && pSystem.loop) {
deltaTime -= pSystem.duration;
} else if(deltaTime >= pSystem.duration && !pSystem.loop) {
Stop();
}
pSystem.Simulate(deltaTime);
pSystem.Play();
}
}
public void Simulate() {
Debug.Log("Start Particle: " + name);
deltaTime = 0;
lastInterval = Time.realtimeSinceStartup;
isSimulate = true;
}
public void Stop() {
isSimulate = false;
deltaTime = 0;
pSystem.Stop();
}
}