funnymummy1119

AutoShooter draft

Apr 18th, 2021 (edited)
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class AutoShooter : MonoBehaviour
  4. {
  5.     Bullet bulletPrefab;
  6.     public int bulletsPerShoot = 1;
  7.     public int magazineSize = 1; //how many time this weapon shoot before reloading
  8.     public float totalSpreadAngle = 0f;
  9.     public float fireRate = 0f; //shoot times per second
  10.     public float reloadRate = 1f; //speed of reloading magazine
  11.    
  12.     Vector3 GunPosition { get => transform.position; }
  13.     Vector3 MuzzlePosition { get => transform.position }
  14.    
  15.     public void ShootBullet(object sender, Vector3 direction)
  16.     {
  17.         BulletBase newBullet = bulletPrefab;
  18.         Instantiate(bulletPrefab, MuzzlePosition, Quaternion.identity);
  19.         newBullet.Setup(direction); //bullet will fly toward direction
  20.     }
  21. }
  22.    
  23.    
Add Comment
Please, Sign In to add comment