void OnCollisionEnter(Collision collision) { Destructible otherDestructible = collision.gameObject.GetComponent <Destructible>(); if (otherDestructible != null) { if (!otherDestructible.invincible) { if (destructibleDealsVelocityDamage) { Vector3 collisionVelocity = new Vector3(0, 0, 0); if (transform.root.gameObject.rigidbody) { collisionVelocity += transform.root.gameObject.rigidbody.velocity; } Rigidbody rigidbodyCollider = collision.collider.transform.root.gameObject.rigidbody; if (rigidbodyCollider) { collisionVelocity -= rigidbodyCollider.velocity; } if (collisionVelocity.magnitude > minVelocityToCauseDamage) { //Debug.Log("Dealing damage due to velocity:"+Mathf.RoundToInt(-collisionVelocity.magnitude*velocityDamageMagnitude)); otherDestructible.AdjustCurrentShield(Mathf.RoundToInt(-collisionVelocity.magnitude * velocityDamageMagnitude)); } } //Debug.Log("Dealing damage due to destructible:"+-damage); otherDestructible.AdjustCurrentShield(-damage); } } }