Exemplo n.º 1
0
    void Update()
    {
        timer += Time.deltaTime;

        if (explode == true)
        {
            Vector3 pozicija = transform.position;
            back.transform.position = pozicija;
            Collider[] hitColliders = Physics.OverlapSphere(pozicija, areaRange);
            particles.Play();
            int i = 0;
            while (i < hitColliders.Length && i < 50)
            {
                enemies[i] = hitColliders[i].gameObject;
                if (enemies[i].tag == "Enemy")
                {
                    enemyHealth = enemies[i].GetComponent <EnemyHealth> ();
                    enemyHealth.TakeDamage(damage, enemies[i].transform.position, 1);
                }
                if (enemies[i].tag == "Bomb")
                {
                    bombHealth = enemies[i].GetComponent <BombHealth> ();
                    bombHealth.TakeDamage(damage, enemies[i].transform.position, 0);
                }
                i++;
            }
            Destroy(gameObject);
        }
    }
Exemplo n.º 2
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            if (shootHit.collider.tag == "Bomb")
            {
                bombHealth = shootHit.collider.GetComponent <BombHealth> ();
                bombHealth.TakeDamage(damage, shootHit.point, effect);
            }
            else
            {
                enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
                if (enemyHealth != null)
                {
                    enemyHealth.TakeDamage(damage, shootHit.point, effect);
                    if (effect == 3)
                    {
                        Explosion.transform.position = shootHit.point;
                        explParticle.Play();
                        Collider[] hitColliders = Physics.OverlapSphere(shootHit.point, 3f);
                        int        i            = 0;
                        while (i < hitColliders.Length && i < 50)
                        {
                            enemies[i] = hitColliders[i].gameObject;
                            if (enemies[i].tag == "Enemy")
                            {
                                enemyHealth = enemies[i].GetComponent <EnemyHealth> ();
                                enemyHealth.TakeDamage(primaryDmg / 2, enemies[i].transform.position, 0);
                            }
                            i++;
                        }
                    }
                }
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }