diff options
Diffstat (limited to 'GameCode/ParticlePlayer.cs')
-rw-r--r-- | GameCode/ParticlePlayer.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/GameCode/ParticlePlayer.cs b/GameCode/ParticlePlayer.cs new file mode 100644 index 0000000..c834a68 --- /dev/null +++ b/GameCode/ParticlePlayer.cs @@ -0,0 +1,53 @@ +using UnityEngine; + +public class ParticlePlayer : MonoBehaviour +{ + public static ParticlePlayer instance; + + private int spawnsThisFrame; + + private void Awake() + { + instance = this; + } + + private void Update() + { + spawnsThisFrame = 0; + } + + public void PlayEffect(string effectName, Vector3 position, Quaternion rotation, float scale = 1f, Transform followTransform = null) + { + if ((float)spawnsThisFrame > 5f) + { + return; + } + spawnsThisFrame++; + Transform transform = base.transform.Find(effectName); + if (!transform) + { + return; + } + if ((bool)followTransform) + { + transform = Object.Instantiate(transform.gameObject, null).transform; + } + transform.transform.position = position; + transform.transform.localScale = scale * Vector3.one; + transform.transform.rotation = rotation; + if ((bool)followTransform) + { + transform.gameObject.AddComponent<FollowLocalPos>().Follow(followTransform); + } + ParticleSystem[] componentsInChildren = transform.GetComponentsInChildren<ParticleSystem>(); + for (int i = 0; i < componentsInChildren.Length; i++) + { + if ((bool)followTransform) + { + ParticleSystem.MainModule main = componentsInChildren[i].main; + main.simulationSpace = ParticleSystemSimulationSpace.Local; + } + componentsInChildren[i].Play(); + } + } +} |