Advertisement
Guest User

HandgunDamage

a guest
Apr 6th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HandgunDamage : MonoBehaviour
  6. {
  7.     public int          Damage;
  8.     public float        TargetDistance;
  9.     public float        MaxRange;
  10.     public float        timer;
  11.     public AudioSource  firingSound;
  12.  
  13.     private float       fireRate;
  14.     public RaycastHit   Shot;
  15.  
  16.     // Start is called before the first frame update
  17.     void Start()
  18.     {
  19.         Damage      = 5;
  20.         MaxRange    = 100;
  21.         fireRate    = 2.75f;
  22.     }
  23.  
  24.     // Update is called once per frame
  25.     void Update()
  26.     {
  27.         if (GlobalInventory.pistolActive && GlobalInventory.Bullets > 0)
  28.         {
  29.             if (Input.GetButton("Fire1") && timer <= 0)
  30.             {
  31.                 firingSound.Play();
  32.                 timer = 1;
  33.                 GlobalInventory.Bullets--;
  34.                 GlobalInventory.CurrentAmmo--;
  35.                 if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Shot))
  36.                 {
  37.                     TargetDistance = Shot.distance;
  38.                     if (TargetDistance < MaxRange && Shot.collider.tag.Equals("Enemy"))
  39.                     {
  40.                         firingSound.Play();
  41.                         EnemyHealth.Damage = 5;
  42.                        //Shot.transform.SendMessage("DeductPoints", Damage, SendMessageOptions.DontRequireReceiver);
  43.                     }
  44.                 }
  45.             }
  46.             timer -= Time.deltaTime * fireRate;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement