using System.Collections.Generic; 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(); public bool Initialized { get; private set; } private void Awake() { 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); } Initialized = true; } private void PlayAll(Vector3? location = null, Quaternion? rotation = null) { if (!Initialized) return; if (VfxExplosionParentInstance) { if (location != null) VfxExplosionParentInstance.transform.position = (Vector3)location; if (rotation != null) VfxExplosionParentInstance.transform.rotation = (Quaternion)rotation; VfxExplosionParticles.ForEach((x) => x.Play()); } } }