Advertisement
lemansky

Untitled

Apr 11th, 2021
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Blaster : MonoBehaviour
  6. {
  7.     public GameObject bulletPrefab;
  8.     public float bulletRate = 0.5f;
  9.     public float bulletCooldown = -1.0f;
  10.  
  11.     public AudioClip bulletClip;
  12.     AudioSource _audioSource;
  13.     void Start()
  14.     {
  15.         _audioSource = GameObject.Find("BulletSound").GetComponent<AudioSource>();
  16.     }
  17.  
  18.     void Update()
  19.     {
  20.         if (Input.GetMouseButtonDown(0) && Time.time > bulletCooldown)
  21.         {
  22.             Instantiate(bulletPrefab, transform.position, transform.rotation);
  23.             bulletCooldown = Time.time + bulletRate;
  24.             _audioSource.PlayOneShot(bulletClip);
  25.         }
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement