Example #1
0
    void OnParticleCollision(GameObject other)
    {
        if (canHit)
        {
            Rigidbody r = other.GetComponent <Rigidbody>();
            if (r)
            {
                PlayerBehaviour     pB = r.GetComponent <PlayerBehaviour>();
                AIBehaviour         aB = r.GetComponent <AIBehaviour>();
                BossBehaviour       bB = r.GetComponent <BossBehaviour>();
                GiantLaserBehaviour gB = r.GetComponent <GiantLaserBehaviour>();
                if (pB)
                {
                    if (!pB.invinsible & !playerImune)
                    {
                        pB.Damage(damageDealt);
                    }
                }
                if (!enemyImune)
                {
                    if (aB)
                    {
                        aB.Damage(damageDealt);

                        aB.ToggleGotHit();
                    }

                    if (bB)
                    {
                        bB.Damage(damageDealt);
                    }
                    if (gB)
                    {
                        gB.Damage(damageDealt);
                    }
                }
                //Vector3 direction = other.transform.position - transform.position;
                //direction = direction.normalized;
                //r.AddForce(direction * 5);
                //Destroy(gameObject);
                canHit = false;
                StartCoroutine(SetCanHitTrue());
            }
        }
    }
Example #2
0
    void OnCollisionEnter()
    {
        if (!collided)
        {
            if (audioS)
            {
                audioS.PlayOneShot(collideAudio);
            }

            //get all the colliders inside the radius
            Collider[] collider = Physics.OverlapSphere(transform.position, explosionRadius);
            for (int i = 0; i < collider.Length; i++)
            {
                //
                Rigidbody r = collider[i].GetComponent <Rigidbody>();
                if (r)
                {
                    PlayerBehaviour     pB = r.GetComponent <PlayerBehaviour>();
                    AIBehaviour         aB = r.GetComponent <AIBehaviour>();
                    BossBehaviour       bB = r.GetComponent <BossBehaviour>();
                    GiantLaserBehaviour gB = r.GetComponent <GiantLaserBehaviour>();

                    Vector3 closetPoint = collider[i].ClosestPointOnBounds(transform.position);
                    float   damageDealt = damage - Vector3.Distance(transform.position, closetPoint) * (damage / explosionRadius);
                    if (pB)
                    {
                        if (!pB.invinsible & !playerImune)
                        {
                            if (damageDealt > 0)
                            {
                                pB.Damage(damageDealt);
                                if (!pB.ragdollh.ragdolled)
                                {
                                    pB.playerAnimator.SetTrigger("GotHit");
                                    if (explosionForce > 10)
                                    {
                                        pB.ToggleRagdoll();
                                        if (!pB.dead)
                                        {
                                            pB.StandUpAfter(2f);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!enemyImune)
                    {
                        if (aB)
                        {
                            if (damageDealt > 0)
                            {
                                aB.Damage(damageDealt);

                                aB.ToggleGotHit();
                            }
                        }

                        if (bB)
                        {
                            if (damageDealt > 0)
                            {
                                bB.Damage(damageDealt);
                            }
                        }
                        if (gB)
                        {
                            if (damageDealt > 0)
                            {
                                gB.Damage(damageDealt);
                            }
                        }
                    }
                    r.AddExplosionForce(explosionForce, transform.position, explosionRadius);
                }
            }
            if (particle)
            {
                Instantiate(particle, transform.position, Quaternion.identity);
            }
            if (trail)
            {
                trail.transform.parent = null;
            }
            collided = true;
            gameObject.GetComponentInChildren <Renderer>().enabled = false;
            try
            {
                gameObject.GetComponentInChildren <ParticleSystem>().Stop();
            }
            catch
            {
                ;
            }
            if (audioS)
            {
                audioS.PlayOneShot(collideAudio);
            }
            StartCoroutine(DestroyThis(1f));
        }
    }