Пример #1
0
    public 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;         // ray currently shoots straight down

        if (Physics.Raycast(shootRay, out shootHit, range))
        {
            /* EnemyHealth enemyHealth = shootHit.collider.GetComponent<EnemyHealth>();
             *      if(enemyHealth != null){
             *              enemyHealth.TakeDamage (damagePerShot, shootHit.point);
             *      }
             */
            if (shootHit.transform.gameObject.tag == "Enemy")
            {
                Debug.Log(shootHit.transform.gameObject.name + " has been hit");
                //Destroy(shootHit.transform.gameObject);
                //Instantiate(explosion, transform.position, transform.rotation);
                Explode explosion = shootHit.transform.gameObject.GetComponent <Explode>();
                explosion.Expode();
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }