Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HandgunDamage : MonoBehaviour
- {
- public int Damage;
- public float TargetDistance;
- public float MaxRange;
- public float timer;
- public AudioSource firingSound;
- private float fireRate;
- public RaycastHit Shot;
- // Start is called before the first frame update
- void Start()
- {
- Damage = 5;
- MaxRange = 100;
- fireRate = 2.75f;
- }
- // Update is called once per frame
- void Update()
- {
- if (GlobalInventory.pistolActive && GlobalInventory.Bullets > 0)
- {
- if (Input.GetButton("Fire1") && timer <= 0)
- {
- firingSound.Play();
- timer = 1;
- GlobalInventory.Bullets--;
- GlobalInventory.CurrentAmmo--;
- if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Shot))
- {
- TargetDistance = Shot.distance;
- if (TargetDistance < MaxRange && Shot.collider.tag.Equals("Enemy"))
- {
- firingSound.Play();
- EnemyHealth.Damage = 5;
- //Shot.transform.SendMessage("DeductPoints", Damage, SendMessageOptions.DontRequireReceiver);
- }
- }
- }
- timer -= Time.deltaTime * fireRate;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement