lemansky

Untitled

Apr 11th, 2021
569
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×