From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/ParticlePlayer.cs | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 GameCode/ParticlePlayer.cs (limited to 'GameCode/ParticlePlayer.cs') 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().Follow(followTransform); + } + ParticleSystem[] componentsInChildren = transform.GetComponentsInChildren(); + for (int i = 0; i < componentsInChildren.Length; i++) + { + if ((bool)followTransform) + { + ParticleSystem.MainModule main = componentsInChildren[i].main; + main.simulationSpace = ParticleSystemSimulationSpace.Local; + } + componentsInChildren[i].Play(); + } + } +} -- cgit v1.1-26-g67d0