Advertisement
leomovskii

GunScript.cs

Nov 29th, 2021
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GunScript : MonoBehaviour {
  6.  
  7.     public Object bullet; // префаб кулі
  8.     public Transform aimPoint; // місце вистрілу
  9.    
  10.     public float reload = 2f; // час перезарядження
  11.     float counter;
  12.    
  13.     void FixedUpdate() {
  14.         if (counter < reload)
  15.             counter += Time.fixedDeltaTime;
  16.     }
  17.  
  18.     void Update() {
  19.         if (counter >= reload && Input.GetMouseButtonDown(0)) {
  20.             GameObject go = (GameObject) Instantiate(bullet);
  21.             go.transform.position = aimPoint.position;
  22.             counter = 0f;
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement