Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System;
- public class Shooting : MonoBehaviour {
- public Transform bullet;
- public GUISkin MySkin;
- public int BulletForce = 5000;
- public int ammo;
- public int MaxAmmoCount = 30;
- public int Clip = 0;
- public int MaxClip = 9;
- public AudioClip Fire;
- public AudioClip Reload;
- public AudioClip Discharge;
- public int AmmoBoxWidth = 200;
- public int AmmoBoxHeight = 100;
- public float ReloadTimer = 1.0f;
- public GameObject maincamera;
- public GameObject camerag;
- public GameObject go2;
- public bool a;
- public bool b;
- public AudioSource source;
- void Start()
- {
- source = GetComponent<AudioSource>();
- source.loop = false;
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(1) && ammo > 0)
- {
- a = !a;
- }
- go2.GetComponent<MeshRenderer> ().enabled = b;
- if (a == true)
- {
- maincamera.gameObject.SetActive(false);
- camerag.gameObject.SetActive(true);
- if (Input.GetKey(KeyCode.Q) && ammo > 0)
- {
- b = !b;
- }
- if (Input.GetMouseButtonDown(0) && ammo > 0 && ReloadTimer <= 0)
- {
- Shoot();
- }
- }
- else if (a == false)
- {
- maincamera.gameObject.SetActive(true);
- camerag.gameObject.SetActive(false);
- b = false;
- }
- if (Input.GetButtonDown("Reload Weapon") && Clip > 0)
- {
- ReloadTimer = 1.0f;
- Clip -= 1;
- ammo = 30;
- GetComponent<AudioSource>().PlayOneShot(Reload);
- }
- if (Clip > MaxClip)
- {
- Clip = MaxClip;
- }
- if (Input.GetButtonDown("Discharge Weapon"))
- {
- ammo = 0;
- GetComponent<AudioSource>().PlayOneShot(Discharge);
- }
- if (ReloadTimer > 0.0f)
- {
- ReloadTimer -= Time.deltaTime;
- }
- }
- void Shoot()
- {
- Transform BulletInstance = (Transform)Instantiate(bullet, GameObject.Find("BulletSpawnPoint").transform.position, Quaternion.identity);
- BulletInstance.GetComponent<Rigidbody>().AddForce(transform.forward * BulletForce);
- ammo -= 1;
- GetComponent<AudioSource>().PlayOneShot(Fire);
- }
- void OnGUI()
- {
- GUI.skin = MySkin;
- GUI.Box(new Rect(Screen.width - AmmoBoxWidth, 0, AmmoBoxWidth, AmmoBoxHeight), "Патронов: " + ammo + "/" + MaxAmmoCount);
- GUI.Label(new Rect(Screen.width - AmmoBoxWidth, 0, AmmoBoxWidth, AmmoBoxHeight), "Обойм: " + Clip + "/" + MaxClip);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement