Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Weapon : MonoBehaviour {
- /* Berkin AKKAYA */
- /* berkinakkaya.wixsite.com/blog */
- [Header("Weapon Specifications")]
- [SerializeField] [Range(0.0f, 10.0f)] float fireRate;
- [SerializeField] float bulletSpawnOffset;
- [SerializeField] GameObject bulletPrefab;
- //Variables used for shooting system
- bool allowFire = false;
- float nextFire = 0;
- #region Update
- void Update(){
- Shoot();
- }
- #endregion
- #region Shooting
- void CreateBullet(){
- GameObject bullet = Instantiate(bulletPrefab);
- bullet.transform.position = transform.position + transform.up * bulletSpawnOffset;
- }
- void Shoot(){
- nextFire -= fireRate * Time.deltaTime;
- if(allowFire && Input.GetMouseButton(0)){
- CreateBullet();
- allowFire = false;
- return;
- }
- if(nextFire <= 0){
- allowFire = true;
- nextFire = 1f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment