using System; using UnityEngine; public class TurnOff_GO : MyCoroutine { public bool NoUseParticleTime = false; public float OffTime = 5f; public eEffectLocation e_EffectLocation; public Action act_End; Actor m_target, m_target2; ProjectileData m_ProjectileData; bool followTarget, isTarget = false, isTarget2 = false; public void Set() { gameObject.SetActive(false); gameObject.SetActive(true); } public void Set(Actor target, ProjectileData pd, float LifeTime) { followTarget = true; m_target = target; isTarget = true; m_ProjectileData = pd; NoUseParticleTime = true; OffTime = LifeTime; transform.position = m_ProjectileData.Get_EffectPos(target); gameObject.SetActive(true); Set_Off(); } public void Set(Actor target, eEffectLocation loca, float lifetime) { m_target2 = target; isTarget2 = true; e_EffectLocation = loca; OffTime = lifetime; gameObject.SetActive(true); Set_Off(); } public void Set_PrefabInfo(Actor target) { Set_Location(target); gameObject.SetActive(true); Set_Off(); } void Set_Off() { Set_Coroutine_withCancel(() => { gameObject.SetActive(false); act_End?.Invoke(); }, NoUseParticleTime ? OffTime : GetComponent().main.duration); } private void OnEnable() { Set_Off(); } void Update() { if (followTarget) { if (!isTarget) { transform.position = Vector3.right * 1000000f; gameObject.SetActive(false); } else { var pos = m_ProjectileData.Get_EffectPos(m_target); transform.position = pos; } } else if (isTarget2) Set_Location(m_target2); } void Set_Location(Actor target) { Vector3 effectPos; switch (e_EffectLocation) { case eEffectLocation.Top: effectPos = target.Get_Top_postion(); break; default: effectPos = target.Get_Center_position(); break; case eEffectLocation.Bottom: effectPos = target.Get_position(); break; } transform.position = effectPos; } }