protected virtual void OnCollisionEnter2D(Collision2D p_collision) { GameObject v_otherCollidedObject = p_collision.gameObject; if (v_otherCollidedObject != null && GetComponent <Rigidbody2D>() != null && !RecentCollidedObjects.Contains(v_otherCollidedObject)) { DamageableBlock v_otherBlock = v_otherCollidedObject.GetComponent <DamageableBlock>(); float v_impactForce = GetImpactForce(p_collision.gameObject); float v_attack = v_otherBlock != null?v_otherBlock.Attack *v_otherBlock.GetForceAttenuation() : (v_otherCollidedObject.GetComponent <Rigidbody2D>() == null ? Attack * 1.5f * this.GetForceAttenuation() : 0); float v_attackImpact = v_impactForce * v_attack; float v_damageApplyed = ApplyDamage(v_attackImpact); if (v_damageApplyed > 0) { RecentCollidedObjects.AddChecking(v_otherCollidedObject.gameObject); } if (p_collision.contacts.Length > 0 && v_damageApplyed > MinDamageToShowCollisionEffect) { if (p_collision.contacts.Length > 0) { StartCollisionEffects(p_collision.contacts[0].point); } } _currentTimeToEnableApplyDamage = _currentTimeToEnableApplyDamage <= 0 ? _maxCurrentTimeToEnableApplyDamage : _currentTimeToEnableApplyDamage; //OldVelocity = rigidbody2D != null? rigidbody2D.velocity : Vector2.zero; } }
private void UpdateTimeToApplyDamage() { _currentTimeToEnableApplyDamage = Mathf.Max(0, _currentTimeToEnableApplyDamage - Time.deltaTime); if (_currentTimeToEnableApplyDamage <= 0 && RecentCollidedObjects.Count > 0) { RecentCollidedObjects.Clear(); } }