Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Weapon : MonoBehaviour
- {
- public int damage;
- public float fireRate; // this takes over the timeBetweenShots variable in the player
- public float reloadSpeed;
- public GameObject bullet;
- public GameObject shootPoint;
- public bool canShoot = true;
- public virtual void Shoot()
- {
- if (canShoot)
- {
- GameObject.Instantiate(bullet, shootPoint.transform.position, shootPoint.transform.rotation);
- CameraShaker.Instance.ShakeOnce(2, 2.5f, .1f, .1f);
- canShoot = false;
- StartCoroutine(ShootDelay(fireRate));
- }
- }
- IEnumerator ShootDelay(float t)
- {
- yield return new WaitForSeconds(t);
- canShoot = true;
- }
- }
- //--------------------------------------------
- //--------------------------------------------
- public class Pistol : Weapon
- {
- private void Start()
- {
- damage = 2;
- fireRate = .7f;
- reloadSpeed = 4;
- }
- public override void Shoot()
- {
- base.Shoot();
- }
- }
- //Inside the Player Controller
- public void Shoot() //Gets called in the Update function
- {
- if (Input.GetMouseButton(0))
- {
- currentWeapon.Shoot();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement