Example #1
0
    void shoot()
    {
        if (shootingAudio != null)
        {
            audioSource.PlayOneShot(shootingAudio);
        }

        if (_scope == null || _scope.IsScoped == 0)
        {
            animator.SetTrigger("shoot");
        }

        transform.parent.transform.parent.GetComponent <MouseLook>().AddRecoil(upRecoil, Random.Range(-sideRecoil, sideRecoil));
        bullets -= 1;
        muzzleFlash.Play();
        RaycastHit hit;

        if (Physics.Raycast(cam.position, cam.forward, out hit, range, interactable))
        {
            interact target = hit.transform.GetComponent <interact>();
            target.Damage(damage);
            target.Hit(hit.point, Quaternion.LookRotation(hit.normal));
            Rigidbody rb = hit.transform.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddForce(force * hit.normal * -1, ForceMode.Impulse);
            }
        }
    }
Example #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (isAttacking)
     {
         interact health = other.GetComponent <interact>();
         if (health != null)
         {
             health.Damage(damage);
         }
     }
 }