Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Blaster : MonoBehaviour
- {
- public GameObject bulletPrefab;
- public float bulletRate = 0.5f;
- public float bulletCooldown = -1.0f;
- public AudioClip bulletClip;
- AudioSource _audioSource;
- void Start()
- {
- _audioSource = GameObject.Find("BulletSound").GetComponent<AudioSource>();
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(0) && Time.time > bulletCooldown)
- {
- Instantiate(bulletPrefab, transform.position, transform.rotation);
- bulletCooldown = Time.time + bulletRate;
- _audioSource.PlayOneShot(bulletClip);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement