Exemplo n.º 1
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.tag == "EnemyProjectile" && !_isInvincible)
     {
         health.takeDamage(20);
     }
 }
Exemplo n.º 2
0
 private void OnTriggerEnter2D(Collider2D target)
 {
     if (target.gameObject.tag == "PlayerBullet")
     {
         health.takeDamage(40);
         Destroy(target.gameObject);
     }
 }
Exemplo n.º 3
0
    void OnTriggerEnter(Collider collider)
    {
        if ((bulletHitMask.value & 1 << collider.gameObject.layer) != 0)
        {
            BulletUtil.deactivateBullet(gameObject);

            switch (bulletType)
            {
            case ShooterTypeEnum.FRIENDLY:
                FriendlyBulletObjectPool.instance.returnPooledObject(gameObject);
                break;

            case ShooterTypeEnum.HOSTILE:
                EnemyBulletObjectPool.instance.returnPooledObject(gameObject);
                break;
            }

            GameObject impactEffectParticleSystem;
            switch (collider.gameObject.layer)
            {
            case 6:     //Player.
                LivesManager.instance.decrementLivesWithInvul();
                break;

            case 9:     // Boundary.
                break;

            case 10:     // Indestructible.
                impactEffectParticleSystem = (GameObject)Instantiate(impactEffect, transform.position, transform.rotation);
                Destroy(impactEffectParticleSystem, 1.0f);
                break;

            default:
                impactEffectParticleSystem = (GameObject)Instantiate(impactEffect, transform.position, transform.rotation);
                Destroy(impactEffectParticleSystem, 1.0f);

                BaseHealth   collidedHealthComponent = collider.gameObject.GetComponent <BaseHealth>();
                BulletDamage damageComponent         = gameObject.GetComponent <BulletDamage>();
                if (collidedHealthComponent != null && damageComponent != null)
                {
                    collidedHealthComponent.takeDamage(damageComponent.damage);
                }
                break;
            }
        }
    }
Exemplo n.º 4
0
    private void Shooting()
    {
        ikc.Shooting = Input.GetKey(KeyCode.Mouse0);

        if (ikc.Shooting)
        {
            if (ikc.LockedOn && damageDone == false)
            {
                PlayMuzzleParticle();
                SoundEngine.instance.PlaySound("pistolShot", transform.position, null);
                damageDone = true;
                //shoot towards target

                if (ikc.CurrentLookAtWeight > 0.8f)
                {
                    if (Physics.Raycast(transform.TransformPoint(0f, 1.7f, 0f), ikc.Target.GetComponent <BaseHealth>().centerPoint - transform.TransformPoint(0f, 1.7f, 0f), out ShootRaycastHit, maxShootingDistance, EnemyLayerMask, QueryTriggerInteraction.Ignore)) //starting point, target point
                    {
                        GameObject g = Instantiate(projectileImpact, ShootRaycastHit.point, Quaternion.identity) as GameObject;
                        g.transform.SetParent(ShootRaycastHit.collider.transform);
                        g.transform.rotation = Quaternion.FromToRotation(g.transform.up, ShootRaycastHit.normal);
                        if (ShootRaycastHit.collider.GetComponent <BaseHealth>())
                        {
                            EnemyHealth = ShootRaycastHit.collider.GetComponent <BaseHealth>();
                            EnemyHealth.takeDamage(GunDamage, gameObject);
                        }
                    }
                }
            }
            else if (damageDone == false)
            {
                PlayMuzzleParticle();
                SoundEngine.instance.PlaySound("pistolShot", transform.position, null);
                damageDone = true;
                scanForFreeAim();

                if (currentFreeAimingTarget)
                {
                    ikc.Target = currentFreeAimingTarget;
                    if (ikc.CurrentLookAtWeight > 0.8f)
                    {
                        if (Physics.Raycast(transform.TransformPoint(0f, 1, 0f), ikc.Target.transform.TransformPoint(0f, 1.4f, 0f) - transform.TransformPoint(0f, 1, 0f), out ShootRaycastHit, maxShootingDistance, EnemyLayerMask, QueryTriggerInteraction.Ignore))
                        {
                            GameObject g = Instantiate(projectileImpact, ShootRaycastHit.point, Quaternion.identity) as GameObject;
                            g.transform.SetParent(ShootRaycastHit.collider.transform);
                            g.transform.rotation = Quaternion.FromToRotation(g.transform.up, transform.position - g.transform.position);
                            if (ShootRaycastHit.collider.GetComponent <BaseHealth>())
                            {
                                EnemyHealth = ikc.Target.GetComponent <BaseHealth>();
                                EnemyHealth.takeDamage(GunDamage, gameObject);
                            }
                        }
                    }
                }
                else
                {
                    if (ikc.CurrentLookAtWeight > 0.8f)
                    {
                        if (Physics.Raycast(transform.TransformPoint(0f, 1.5f, 0f), transform.forward, out ShootRaycastHit, maxShootingDistance, EnemyLayerMask, QueryTriggerInteraction.Ignore))
                        {
                            GameObject g = (GameObject)Instantiate(projectileImpact, ShootRaycastHit.point, Quaternion.identity);
                            g.transform.rotation = Quaternion.FromToRotation(g.transform.up, ShootRaycastHit.normal);
                        }
                    }

                    ikc.Target = null;
                }
            }
        }
        else
        {
            currentFreeAimingTarget = null;
            if (!ikc.LockedOn)
            {
                ikc.Target = null;
            }
        }
    }