void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Enemy")
        {
            EnemyBaseAIBehaviour enemy = other.GetComponent <EnemyBaseAIBehaviour>();

            //Mosquito has the collider in a children object so we need to search for script in parent
            if (enemy == null)
            {
                enemy = other.GetComponentInParent <EnemyBaseAIBehaviour>();
            }

            if (enemy != null)
            {
                bb.enemiesInRange.Add(enemy);
            }
        }
        else if (other.tag == "Shot")
        {
            EnemyShotControllerBase shot = other.GetComponent <EnemyShotControllerBase>();

            if (shot != null)
            {
                bb.shotsInRange.Add(shot);
            }
        }
        else if (other.tag == "WormHead")
        {
            WormAIBehaviour worm = other.GetComponent <WormAIBehaviour>();

            if (worm != null)
            {
                bb.worm = worm;
                worm.SpecialAttackInRange();
            }
        }
        else if (other.tag == "Vortex")
        {
            VortexController vortex = other.GetComponent <VortexController>();

            if (vortex != null)
            {
                bb.vortexInRange.Add(vortex);
            }
        }
        else if (other.tag == "Turret")
        {
            TurretAIBehaviour turret = other.GetComponent <TurretAIBehaviour>();

            if (turret != null)
            {
                bb.turretsInRange.Add(turret);
            }
        }
    }
Example #2
0
 void OtherVortexIsNear()
 {
     for (int i = 0; i < DataList.vortexs.Count; i++)
     {
         GameObject vortex = DataList.vortexs[i];
         if (vortex.transform.position != transform.position)
         {
             float distancia = (transform.position - vortex.transform.position).magnitude;
             if (distancia <= 3)
             {
                 VortexController vortexTargeting = vortex.GetComponent <VortexController>();
                 vortexTargeting.DieVortex();
                 DataList.vortexs.RemoveAt(i);
             }
         }
     }
 }
    void OnCollisionEnter(Collision collision)
    {
        //Stop shot
        rigidBody.velocity = Vector3.zero;
        projectileParticle.SetActive(false);

        impactParticle.GetComponent <AudioSource>().clip = wrongImpact;

        if (collision.collider.tag == "Enemy")
        {
            EnemyBaseAIBehaviour enemy = collision.collider.GetComponent <EnemyBaseAIBehaviour>();
            if (enemy == null)
            {
                enemy = collision.collider.GetComponentInParent <EnemyBaseAIBehaviour>();
            }

            if (enemy != null)
            {
                if (enemy.color == color)
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }

                enemy.ImpactedByShot(color, damage, transform.forward * forceMultiplier, player);
            }
        }
        else if (collision.collider.tag == "Vortex")
        {
            VortexController vortex = collision.collider.GetComponent <VortexController>();
            if (vortex != null)
            {
                vortex.ImpactedByShot(color, damage, player);
                if (vortex.Active)
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }
                else
                {
                    impactParticle.GetComponent <AudioSource>().clip = wrongImpact;
                }
            }
        }
        else if (collision.collider.tag == "Barrel")
        {
            CapacitorImpacted barrel = collision.collider.GetComponent <CapacitorImpacted>();
            if (barrel != null)
            {
                barrel.controller.ImpactedByShot(color, player);
            }

            impactParticle.GetComponent <AudioSource>().clip = goodImpact;
        }
        else if (collision.collider.tag == "WormBody")
        {
            WormBodySegmentController worm = collision.collider.GetComponent <WormBodySegmentController>();
            if (worm != null)
            {
                if (worm.Color == color)
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }

                worm.ImpactedByShot(color, damage, player);
            }
        }
        else if (collision.collider.tag == "WormHead")
        {
            WormAIBehaviour worm = collision.collider.GetComponent <WormAIBehaviour>();
            if (worm != null)
            {
                worm.ImpactedByShot(color, damage, player);
            }

            impactParticle.GetComponent <AudioSource>().clip = goodImpact;
        }
        else if (collision.collider.tag == "Hexagon")
        {
            HexagonController hexagon = collision.collider.GetComponentInParent <HexagonController>();
            if (hexagon != null)
            {
                hexagon.ImpactedByShot(player);
                if (hexagon.HasActiveTurret())
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }
                else
                {
                    impactParticle.GetComponent <AudioSource>().clip = wrongImpact;
                }
            }
        }

        if (collision.contacts.Length > 0)
        {
            impactParticle.transform.rotation = Quaternion.FromToRotation(Vector3.up, collision.contacts[0].normal);
        }
        impactParticle.SetActive(true);

        shotCollider.enabled = false;
        //We let the impactParticle do its job
        StartCoroutine(WaitAndReturnToPool());
    }