Beispiel #1
0
    void OnHit(Vector3 point, Vector3 normal, Collider collider)
    {
        Damageable damageable = null;

        // damage
        if (areaOfDamage)
        {
            // area damage
            areaOfDamage.InflictDamageInArea(damage, point, hittableLayers, k_TriggerInteraction, m_ProjectileBase.owner);
        }
        else
        {
            // point damage
            damageable = collider.GetComponent <Damageable>();
            if (damageable)
            {
                damageable.InflictDamage(damage, false, m_ProjectileBase.owner);
                m_ProjectileBase.OnHit(m_Velocity);
            }
        }

        // impact vfx
        if (impactVFX)
        {
            GameObject impactVFXInstance = Instantiate(impactVFX, point + (normal * impactVFXSpawnOffset), Quaternion.LookRotation(normal));
            if (impactVFXLifetime > 0)
            {
                Destroy(impactVFXInstance.gameObject, impactVFXLifetime);
            }
        }

        // impact sfx
        if (impactSFXClip)
        {
            if (damageable && damageable.damageMultiplier > 0f)
            {
                AudioUtility.CreateSFX(damageSFXClip, point, AudioUtility.AudioGroups.Impact, 0.6f, 1f, 100f, 1f);
            }
            else
            {
                AudioUtility.CreateSFX(impactSFXClip, point, AudioUtility.AudioGroups.Impact, 1f, 3f, 5f);
            }
        }

        // Self Destruct
        Destroy(this.gameObject);
    }