Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class GunControl : MonoBehaviour {
- public GameObject bulletPrefab;
- public Transform pointShot;
- public float delay;
- public float powerShots = 300f;
- public Button buttonShot;
- public float RechargeTime = 5;
- public Slider sliderY;
- public Slider sliderX;
- private float maxRechargeTime;
- private bool timerBool = false;
- private bool delayBeforeFiring = false;
- //sound
- public AudioClip soundFire;
- public AudioClip soundRecharge;
- //sound
- void Start () {
- maxRechargeTime = RechargeTime;
- }
- void Update () {
- Timer();
- Delay();
- }
- void Delay () {
- if(delayBeforeFiring){
- buttonShot.interactable = false;
- sliderX.interactable = false;
- sliderY.interactable = false;
- if(audio.clip == null)
- audio.PlayOneShot(soundRecharge);
- }
- else
- {
- buttonShot.interactable = true;
- sliderX.interactable = true;
- sliderY.interactable = true;
- audio.Stop();
- }
- }
- void Timer () {
- if(RechargeTime >= 0 && timerBool){
- RechargeTime -= Time.deltaTime;
- }
- if(RechargeTime <= 0) {
- delayBeforeFiring = false;
- timerBool = false;
- RechargeTime = maxRechargeTime;
- }
- }
- public void ShotButton () {
- Invoke("Shot", delay);
- }
- void Shot() {
- RaycastHit hit;
- Ray ray = new Ray(pointShot.localPosition, -Vector3.forward);
- timerBool = true;
- audio.PlayOneShot(soundFire);
- if(!delayBeforeFiring){
- if (Physics.Raycast(ray, out hit))
- Instantiate(bulletPrefab, hit.point, transform.rotation);
- }
- delayBeforeFiring = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement