using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; [CreateAssetMenu(menuName = "Custom/VfxHandler", fileName = "NewVfxHandler")] public class VfxHandlerBase : ScriptableObject { [Header("VFX Dependencies")] public GameObject VfxExplosion; private GameObject VfxExplosionParentInstance; private List VfxExplosionParticles = new List(); private void OnEnable() { GenerateInstance(); } private void GenerateInstance() { VfxExplosionParticles.Clear(); if (VfxExplosion) { VfxExplosionParentInstance = Instantiate(VfxExplosion, Vector3.one, Quaternion.identity); var foundParticleSystems = VfxExplosionParentInstance.GetComponentsInChildren(); VfxExplosionParticles.AddRange(foundParticleSystems); VfxExplosionParticles.ForEach((x) => x.transform.localScale = Vector3.one); } } public void PlayAll(Vector3? location = null, Quaternion? rotation = null) { if (!VfxExplosionParentInstance) GenerateInstance(); if (location != null) VfxExplosionParentInstance.transform.position = (Vector3)location; if (rotation != null) VfxExplosionParentInstance.transform.rotation = (Quaternion)rotation; VfxExplosionParticles.ForEach((x) => x.Play()); } }