Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. public abstract class Weapon : MonoBehaviour
  2. {
  3.     public int damage;
  4.     public float fireRate; // this takes over the timeBetweenShots variable in the player
  5.     public float reloadSpeed;
  6.     public GameObject bullet;
  7.     public GameObject shootPoint;
  8.     public bool canShoot = true;
  9.  
  10.     public virtual void Shoot()
  11.     {
  12.         if (canShoot)
  13.         {
  14.             GameObject.Instantiate(bullet, shootPoint.transform.position, shootPoint.transform.rotation);
  15.             CameraShaker.Instance.ShakeOnce(2, 2.5f, .1f, .1f);
  16.             canShoot = false;
  17.             StartCoroutine(ShootDelay(fireRate));
  18.         }
  19.     }
  20.  
  21.     IEnumerator ShootDelay(float t)
  22.     {
  23.         yield return new WaitForSeconds(t);
  24.         canShoot = true;
  25.     }
  26. }
  27.  
  28. //--------------------------------------------
  29. //--------------------------------------------
  30.  
  31. public class Pistol : Weapon
  32. {
  33.     private void Start()
  34.     {
  35.         damage = 2;
  36.         fireRate = .7f;
  37.         reloadSpeed = 4;
  38.     }
  39.  
  40.     public override void Shoot()
  41.     {
  42.         base.Shoot();
  43.     }
  44. }
  45.  
  46. //Inside the Player Controller
  47.     public void Shoot() //Gets called in the Update function
  48.     {
  49.         if (Input.GetMouseButton(0))
  50.         {
  51.             currentWeapon.Shoot();
  52.         }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement