Advertisement
kadyr

Untitled

Sep 19th, 2021
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Gun : MonoBehaviour
  6. {
  7.     [SerializeField]
  8.     protected Transform riffleStart;
  9.  
  10.     [SerializeField]
  11.     protected GameObject bullet;
  12.  
  13.     protected int damage = 0;
  14.     protected float speed = 20f;
  15.     protected float cooldown = 0;
  16.     protected bool auto = false;
  17.  
  18.     private float timer = 0;
  19.  
  20.     public void Shoot()
  21.     {
  22.         if (Input.GetMouseButtonDown(0) || auto)
  23.         {
  24.             if (timer > cooldown)
  25.             {
  26.                 OnShoot();
  27.                 timer = 0;
  28.             }
  29.         }
  30.     }
  31.  
  32.     protected virtual void OnShoot(){ }
  33.    
  34.     void Start()
  35.     {
  36.         timer = cooldown;
  37.     }
  38.  
  39.     // Update is called once per frame
  40.     void Update()
  41.     {
  42.         timer += Time.deltaTime;
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement