Ejemplo n.º 1
0
        void Shoot()
        {
            timer = 0f;
            gunAudio.Play();
            gunLight.enabled  = true;
            faceLight.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.gameObject.CompareTag("Finish"))
                {
                    Debug.Log("entro");
                    EnemyHealth resistencia = shootHit.collider.gameObject.GetComponent <EnemyHealth>();
                    if (resistencia != null)
                    {
                        resistencia.RegistrarImpacto(shootHit.point);
                        gunLine.SetPosition(1, shootHit.point);
                    }
                    else
                    {
                        Destroy(shootHit.collider.gameObject, 1f);
                    }
                }

                EnemyHealth enemyHealth = shootHit.collider.gameObject.GetComponent <EnemyHealth>();
                if (enemyHealth != null)
                {
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                }

                gunLine.SetPosition(1, shootHit.point);
            }

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