// For higher performance assumes that slowFractions contains rb protected bool SlowDown(Rigidbody2D rb, float frac) { if (rb == null) { return(false); } SlowData slowData = slowFractions[rb]; if (slowData.isInside && slowData.slowFrac > slowFraction) { float frac_ = Mathf.Min(frac, slowData.slowFrac - slowFraction); rb.velocity *= 1 - frac_ / slowData.slowFrac; rb.angularVelocity *= 1 - frac_ / slowData.slowFrac; slowData.slowFrac -= frac_; foreach (var keeper in rb.GetComponents <SlowKeeper>()) { keeper.slowFactor = slowData.slowFrac; } foreach (var keeper in rb.GetComponentsInChildren <SlowKeeper>()) { keeper.slowFactor = slowData.slowFrac; } return(true); } return(slowData.isInside); }
// power는 1이 최댓값. 0 = 0%, 1 = 100%. public static void Create(GameObject obj, float power, float time) { var SE_Obj = obj.GetComponent <StatusEffect_Object>(); if (SE_Obj is null) { return; } SlowData d = new SlowData() { power = power, time = time, t = 0 }; power = Mathf.Min(power, 1f); StatusEffect_Slow slow = obj.GetComponent <StatusEffect_Slow>(); if (slow.IsNull()) { slow = obj.AddComponent <StatusEffect_Slow>(); } slow.slows.Add(d); // 모든 옵션에 관한, 디폴트 우선 순위 설정, 높을수록 우선순위가 높음. slow.priority = 8; slow.pow = power; }