コード例 #1
0
    protected virtual void ExplodeOnHit(RaycastHit hit)
    {
        var g = hit.collider.gameObject;
        var t = hit.collider.transform;

        transform.position = hit.point + transform.rotation * Vector3.forward;
        bool glass = g.tag == "glass";

        var m = t.GetMonoBehaviorInParrent();

        if (!explodeOnDestroy)
        {
            var r = hit.rigidbody;

            var rt = transform.rotation;
            if (r != null && r.velocity.magnitude < 20 && r.gameObject.GetComponent <Player>() == null)
            {
                r.AddForceAtPosition(rt * new Vector3(0, 0, ExpForce * hit.rigidbody.mass / hit.collider.bounds.size.magnitude * 500) * fdt, hit.point);
            }
        }
        Destroible destroible = m as Destroible;

        if (g.layer == LayerMask.NameToLayer("Level") || g.layer == LayerMask.NameToLayer("Glass"))
        {
            _Game.AddDecal(glass ? DecalTypes.glass : (decalhole ? DecalTypes.Hole : DecalTypes.Decal),
                           hit.point - rot * Vector3.forward * 0.12f, hit.normal, t);
        }

        if (destroible is Zombie && _SettingsWindow.Blood)
        {
            _Game.particles[(int)ParticleTypes.BloodSplatters].Emit(hit.point, transform.rotation);
            RaycastHit h;
            if (Physics.Raycast(new Ray(pos, new Vector3(0, -1, 0)), out h, 10, 1 << LayerMask.NameToLayer("Level") | LayerMask.NameToLayer("MapItem")))
            {
                _Game.AddDecal(
                    DecalTypes.Blood,
                    h.point - new Vector3(0, -1, 0) * 0.1f,
                    h.normal, _Game.decals.transform);
            }
        }
        else
        {
            _Game.particles[(int)ParticleTypes.particle_metal].Emit(hit.point, transform.rotation);
        }
        if (destroible != null && destroible.isController && destroible.Alive && destroible.isEnemy(OwnerID))
        {
            destroible.RPCSetLifeLocal(destroible.Life - damage * damageFactor(destroible), OwnerID);
        }

        bool staticfield = g.name.ToLower().StartsWith("staticfield");
        bool box         = g.GetComponent <Box>() != null;

        if (staticfield)
        {
            Force = Quaternion.LookRotation(hit.point - g.transform.position) * Vector3.forward * Force.magnitude;
        }
        if (!glass && !staticfield)
        {
            probivaemost--;
        }
        if (probivaemost < 0 || box)
        {
            if (explodeOnDestroy)
            {
                Explode(hit.point);
            }
            Destroy(gameObject);
        }
    }