-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoinParticleController.cs
101 lines (101 loc) · 3.86 KB
/
CoinParticleController.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinParticleController : MonoBehaviour {
bool lastRainbowMode = false;
int lastColorMode = 0;
ParticleSystem sparkles;
ParticleSystem glow;
ParticleSystem glow1;
ParticleSystem glow2;
ParticleSystem glow3;
Dictionary<int, ParticleSystem> dict = new Dictionary<int, ParticleSystem> ();
// Use this for initialization
void Start () {
glow = transform.Find ("Glow").GetComponent<ParticleSystem> ();
glow1 = transform.Find ("Glow1").GetComponent<ParticleSystem> ();
glow2 = transform.Find ("Glow2").GetComponent<ParticleSystem> ();
glow3 = transform.Find ("Glow3").GetComponent<ParticleSystem> ();
sparkles = transform.Find ("Sparkle").GetComponent<ParticleSystem> ();
dict.Add (1, glow);
dict.Add (2, glow1);
dict.Add (3, glow2);
dict.Add (4, glow3);
glow1.Stop ();
glow2.Stop ();
glow3.Stop ();
glow.Stop ();
sparkles.Stop ();
lastRainbowMode = ColorBarController.instance.rainbowMode;
lastColorMode = ColorBarController.instance.colorMode;
}
// Update is called once per frame
void PlayRainbow () {
//print ("----");
//print (ColorBarController.instance.colorMode + 1);
foreach (KeyValuePair<int, ParticleSystem> pair in dict) {
if (pair.Key == (ColorBarController.instance.colorMode + 1)) {
if (pair.Value.isPlaying == false) {
pair.Value.Play ();
//print (pair.Key + " played");
}
} else {
if (pair.Value.isPlaying) {
pair.Value.Pause ();
pair.Value.Stop (true, ParticleSystemStopBehavior.StopEmittingAndClear);
//print (pair.Key + " stopped");
//print ("After" + pair.Value.isPlaying);
}
}
//print (pair.Key + " " + pair.Value.isPlaying);
}
//print (ColorBarController.instance.colorMode);
//print ("Yellow glow Plauin: " + glow.isPlaying);
}
void StopRainbow () {
foreach (KeyValuePair<int, ParticleSystem> pair in dict) {
if (pair.Key == (ColorBarController.instance.colorMode)) {
if (pair.Value.isPlaying == false) {
pair.Value.Play ();
}
} else {
if (pair.Value.isPlaying) {
pair.Value.Pause ();
pair.Value.Stop (true, ParticleSystemStopBehavior.StopEmittingAndClear);
}
}
}
}
void Update () {
if (lastColorMode != ColorBarController.instance.colorMode) {
if (ColorBarController.instance.rainbowMode == true) {
PlayRainbow ();
if (sparkles.isPlaying == false) {
sparkles.Play ();
}
} else {
if (sparkles.isPlaying == true) {
sparkles.Stop ();
}
StopRainbow ();
}
lastRainbowMode = ColorBarController.instance.rainbowMode;
lastColorMode = ColorBarController.instance.colorMode;
}
if (lastRainbowMode != ColorBarController.instance.rainbowMode) {
if (ColorBarController.instance.rainbowMode == true) {
PlayRainbow ();
if (sparkles.isPlaying == false) {
sparkles.Play ();
}
} else {
if (sparkles.isPlaying == true) {
sparkles.Stop ();
}
StopRainbow ();
}
lastColorMode = ColorBarController.instance.colorMode;
lastRainbowMode = ColorBarController.instance.rainbowMode;
}
}
}