void Shoot()
    {
        Vector3 ubication = new Vector3(player.transform.position.x,
                                        player.transform.position.y + 1.1f,
                                        player.transform.position.z);

        timer = 0f;

        gunLine.enabled    = true;
        gunLight.enabled   = true;
        shootRay.origin    = ubication;
        shootRay.direction = transform.forward;
        gunLine.SetPosition(0, ubication);

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            //Destroy (shootHit.collider.gameObject);
            gunLine.SetPosition(1, shootHit.point);
            Resistance resist = shootHit.collider.gameObject.GetComponent <Resistance> ();
            if (resist != null)
            {
                Debug.Log(resist);
                resist.shooted(shootHit.point);
            }
        }
        else
        {
            Debug.Log("No hit");
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
Example #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))
        {
            EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();

            Resistance resistance = shootHit.collider.GetComponent <Resistance> ();

            //Debug.Log (shootHit.collider.gameObject);

            if (resistance != null)
            {
                resistance.shooted(shootHit.point);
            }

            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);
            }



            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }