示例#1
0
    // handle damage from fast collisions
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.GetComponent <Harpoon>())
        {
            return;
        }

        if (collision.relativeVelocity.magnitude > 5f)
        {
            camFX.HighShake();
            playerSoundManager.HeavyImpact();
            // Major hit
            if (lastCollisionTime + collisionCooldown < Time.time)
            {
                lastCollisionTime = Time.time;
                TakeDamage(1);
                // damage animation
                // collision sound
            }
        }
        else if (collision.relativeVelocity.magnitude > 3f)
        {
            // Minor hit
            camFX.MedShake();
            playerSoundManager.MedImpact();
        }
        else if (collision.relativeVelocity.magnitude > 1f)
        {
            // Very minor hit
            camFX.LowShake();
            playerSoundManager.LowImpact();
        }
    }