void Shoot()
    {
        if (Time.time > nextFire)
        {
            nextFire = Time.time + rateOfFire;

            currentAmmo--;

            gunAS.PlayOneShot(shootAC);

            StartCoroutine(WeaponEffects());

            if (Physics.Raycast(shootPoint.position, shootPoint.forward, out hit, weaponRange))
            {
                if (hit.transform.tag == "Enemy")
                {
                    Debug.Log("Hit Enemy");
                    EnemyHealth enemyHealthScript = hit.transform.GetComponent <EnemyHealth>();
                    enemyHealthScript.DeductHealth(damageEnemy);
                }
                else
                {
                    Debug.Log("Hit Something Else");
                }
            }
        }
    }
Пример #2
0
    void Shoot()
    {
        if (Time.time > NextFire)
        {
            NextFire = Time.time + RateofFire;

            currentammo--;

            GunAS.PlayOneShot(ShootAC);

            StartCoroutine(WeaponEffects());

            if (Physics.Raycast(ShootPoint.position, ShootPoint.forward, out Hit, WeaponRange))
            {
                if (Hit.transform.tag == "Enemy")
                {
                    Debug.Log("Hit Enemy");
                    EnemyHealth EnemyHealthScript = Hit.transform.GetComponent <EnemyHealth>();
                    EnemyHealthScript.DeductHealth(damageEnemy);
                    currentammo = currentammo + 10000;
                }
                else
                {
                    Debug.Log("Hit Something Else");
                }
                if (Hit.transform.tag == "Ammo")
                {
                    Debug.Log("Got Ammo!");
                    AmmoPickup AmmoPickupScript = Hit.transform.GetComponent <AmmoPickup>();
                    AmmoPickupScript.DeductHealth(damageAmmo);
                    currentammo = currentammo + 10000;
                }
            }
        }
    }
Пример #3
0
    //when the shoot gun methood is called
    void Shoot()
    {
        //if Time is greater than nextFire
        if (Time.time > nextFire)
        {
            nextFire = Time.time + rateOfFire; // sets next fire equal to the time and rate of fire
            currentAmmo--;                     //and uses one ammo
            GunFire();                         // calls the GunFire method
            StartCoroutine(WeaponEffects());   // calls the StartCoroutine method


            //checking for what the ray cast hits
            //if  the position of the ray cast has hit somthing and that it is still in the weapon range
            if (Physics.Raycast(shootPoint.position, shootPoint.forward, out hit, weaponRange))
            {
                //if the object hit was the enemy
                if (hit.transform.tag == "Enemy")
                {
                    Debug.Log("hit enemy");                                                     //prints to debug log that enemy was hit
                    EnemyHealth enemyHealthScript = hit.transform.GetComponent <EnemyHealth>(); //sets the enemy health script the remaining health from the enemyhealth var
                    enemyHealthScript.DeductHealth(damageEnemy);                                //calls the deductHealth methood for class  the enemy health script to deduct the health
                }
                else
                {
                    Debug.Log("hit Something Else");//prints to the de bug log saying somthing else was hit
                }
            }
        }
    }
Пример #4
0
    private void Fire()
    {
        AudioManager.instance.Play("Shoot");

        muzzleFlash.Play();
        currentAmmo--;
        RaycastHit hit;



        if (Physics.Raycast(fpsCam.position, fpsCam.forward, out hit, range))
        {
            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
                //Debug.Log("стрельнул");
            }

            Quaternion impactRotation = Quaternion.LookRotation(hit.normal);
            GameObject impact         = Instantiate(impactEffect, hit.point, impactRotation);
            impact.transform.parent = hit.transform;
            if (hit.transform.tag == "Enemy")
            {
                //Debug.Log("попал");
                EnemyHealth enemyHealthScript = hit.transform.GetComponent <EnemyHealth>();
                enemyHealthScript.DeductHealth(damage);
            }
            Destroy(impact, 5);
        }
    }
Пример #5
0
 void ShootRay()
 {
     if (Physics.Raycast(shootPoint.position, shootPoint.forward, out hit, weaponRange))
     {
         if (hit.transform.tag == "Enemy")
         {
             //Debug.Log("Hit Enemy");
             EnemyHealth enemyHealthScript = hit.transform.GetComponent <EnemyHealth>();
             enemyHealthScript.DeductHealth(damageEnemy);
             Instantiate(bloodEffect, hit.point, transform.rotation);
         }
         else if (hit.transform.tag == "Head")
         {
             //Debug.Log("Hit Enemy");
             EnemyHealth enemyHealthScript = hit.transform.GetComponentInParent <EnemyHealth>();
             enemyHealthScript.DeductHealth(headShotDamage);
             gunAS.PlayOneShot(headShotAC);
             Instantiate(bloodEffect, hit.point, transform.rotation);
             hit.transform.gameObject.SetActive(false);
         }
         else
         {
             Debug.Log(hit.transform.name);
         }
     }
 }
Пример #6
0
    void Shoot()
    {
        if (!MenuPausa.isPaused)
        {
            if (Time.time > nextFire)
            {
                nextFire = Time.time + rateOfFire;

                ShootingSound();
                ShootingAnimation();



                if (Physics.Raycast(shootPoint.position, shootPoint.forward, out hit, weaponRange))
                {
                    if (hit.transform.tag == "Enemy")
                    {
                        Debug.Log("Hit enemy");
                        EnemyHealth enemyHealthScript = hit.transform.GetComponent <EnemyHealth>();
                        enemyHealthScript.DeductHealth(damageEnemy);
                    }
                    else
                    {
                        Debug.Log("Hit anything");
                    }
                }
            }
        }
    }
Пример #7
0
 void ShootRay()
 {
     if (Physics.Raycast(shootPoint.position, shootPoint.forward, out hit, weaponRange, layer))
     {
         if (hit.transform.tag == "Enemy")
         {
             EnemyHealth enemyHealthScript = hit.transform.GetComponent <EnemyHealth>();
             enemyHealthScript.DeductHealth(damageEnemy);
             Instantiate(bloodEffect, hit.point, transform.rotation);
         }
         else if (hit.transform.tag == "Head")
         {
             EnemyHealth enemyHealthScript = hit.transform.GetComponentInParent <EnemyHealth>();
             enemyHealthScript.DeductHealth(headShotDamage);
             gunAS.PlayOneShot(headShotAC);
             Instantiate(bloodEffect, hit.point, transform.rotation);
             hit.transform.gameObject.SetActive(false);
         }
         else if (hit.transform.tag == "Metal")
         {
             gunAS.PlayOneShot(shootMetalAC);
             Instantiate(metalBulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
         }
         else
         {
             Debug.Log(hit.transform.name);
         }
     }
 }
Пример #8
0
    public float HitWithLaser = 10f; //=> the laser shots with the mouse button


    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Enemy"))
        {
            EnemyHealth enemyHealthScript = other.transform.GetComponent <EnemyHealth>();
            enemyHealthScript.DeductHealth(HitWithLaser);
        }
    }
Пример #9
0
    //private void OnCollisionEnter(Collision other)
    //{
    //if (LayerMask.LayerToName(other.collider.gameObject.layer) == "Enemy")
    //{
    //EnemyHealth enemyHealthScript = other.collider.GetComponent<EnemyHealth>();
    //enemyHealthScript.DeductHealth(damageEnemy);
    //}
    //}

    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            EnemyHealth enemyHealthScript = other.GetComponent <Collider>().GetComponent <EnemyHealth>();
            enemyHealthScript.DeductHealth(damageEnemy);
        }
        if (other.gameObject.CompareTag("Boss"))
        {
            BossHealth bossHealthScript = other.GetComponent <Collider>().GetComponent <BossHealth>();
            bossHealthScript.DeductHealth(damageEnemy);
        }
    }
Пример #10
0
    void shootRay()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, range))
        {
            GameObject laser = GameObject.Instantiate(m_shotPrefab, transform.position, transform.rotation) as GameObject;
            laser.GetComponent <ShotBehavior>().setTarget(hit.point);
            GameObject.Destroy(laser, 2f);
            if (hit.transform.tag == "Enemy")
            {
                LaserImpact.Play();
                CinemachineShake.Instance.ShakeCamera(0.8f, 0.1f);
                EnemyHealth enemyHealthScript = hit.transform.GetComponent <EnemyHealth>();
                enemyHealthScript.DeductHealth(HitWithLaser);
            }
            else
            {
                CinemachineShake.Instance.ShakeCamera(0.5f, 0.1f);
                LaserImpactonWall.Play();
            }
        }
    }