Exemple #1
0
        ///  Default method for Projectiles to perform destruction based on impactType in my Destruction system.
        /// You can use it or override, and so on - everything is permitted. ;)
        public void PerformDestruction()
        {
            if (hit.collider.GetComponent <Fragment>() != null)
            {
                switch (impactType)
                {
                case ImpactType.NoImpact:  {
                    break;
                }

                case ImpactType.Point:  {
                    Fragment frag = hit.collider.GetComponent <Fragment>();
                    if (frag.isIndestructible)
                    {
                        return;
                    }

                    frag.SpawnDirectionalDebris(frag.transform.position - transform.position, velocity);
                    frag.DestroyFragment();

                    break;
                }

                case ImpactType.InnerOnly:  {
                    Collider[] frags;
                    Fragment   frag;

                    /// Inner radius - Fragments turn into debris.
                    frags = Physics.OverlapSphere(hit.point, innerRadius);
                    for (int i = 0; i < frags.Length; i++)
                    {
                        frag = frags[i].GetComponent <Fragment>();
                        if (frag == null || frag.isIndestructible)
                        {
                            continue;
                        }

                        frag.SpawnDirectionalDebris(frag.transform.position - transform.position, velocity);
                        frag.DestroyFragment();
                    }

                    break;
                }

                case ImpactType.OuterOnly:  {
                    Collider[] frags;
                    Fragment   frag;

                    /// Outer radius - Fragments go out of the Element.
                    frags = Physics.OverlapSphere(hit.point, outerRadius);
                    for (int i = 0; i < frags.Length; i++)
                    {
                        frag = frags[i].GetComponent <Fragment>();
                        if (frag == null || frag.isIndestructible)
                        {
                            continue;
                        }

                        frag.DestroyFragment(true);
                    }

                    break;
                }

                case ImpactType.Bispherical:  {
                    Collider[] frags;
                    Fragment   frag;

                    /// Inner radius - Fragments turn into debris.
                    frags = Physics.OverlapSphere(hit.point, innerRadius);
                    for (int i = 0; i < frags.Length; i++)
                    {
                        frag = frags[i].GetComponent <Fragment>();
                        if (frag == null || frag.isIndestructible)
                        {
                            continue;
                        }

                        frag.SpawnDirectionalDebris(frag.transform.position - transform.position, velocity);
                        frag.DestroyFragment();
                    }

                    /// Outer radius - Fragments go out of the Element.
                    frags = Physics.OverlapSphere(hit.point, outerRadius);
                    for (int i = 0; i < frags.Length; i++)
                    {
                        /// Note: we don't want to manage inner radius Fragments here
                        /// (they will be already marked as destroyed).
                        frag = frags[i].GetComponent <Fragment>();
                        if (frag == null || frag.isDestroyed || frag.isIndestructible)
                        {
                            continue;
                        }

                        frag.DestroyFragment(true);
                    }

                    break;
                }
                }
            }
        }