Advertisement
KorolevDmitry123

Untitled

Jul 14th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4.  
  5. public class Shooting : MonoBehaviour {
  6. public Transform bullet;
  7. public GUISkin MySkin;
  8. public int BulletForce = 5000;
  9. public int ammo;
  10. public int MaxAmmoCount = 30;
  11. public int Clip = 0;
  12. public int MaxClip = 9;
  13. public AudioClip Fire;
  14. public AudioClip Reload;
  15. public AudioClip Discharge;
  16. public int AmmoBoxWidth = 200;
  17. public int AmmoBoxHeight = 100;
  18. public float ReloadTimer = 1.0f;
  19. public GameObject maincamera;
  20. public GameObject camerag;
  21. public GameObject go2;
  22. public bool a;
  23. public bool b;
  24. public AudioSource source;
  25. void Start()
  26. {
  27. source = GetComponent<AudioSource>();
  28. source.loop = false;
  29. }
  30. void Update()
  31. {
  32. if (Input.GetMouseButtonDown(1) && ammo > 0)
  33. {
  34. a = !a;
  35. }
  36. go2.GetComponent<MeshRenderer> ().enabled = b;
  37. if (a == true)
  38. {
  39. maincamera.gameObject.SetActive(false);
  40. camerag.gameObject.SetActive(true);
  41. if (Input.GetKey(KeyCode.Q) && ammo > 0)
  42. {
  43. b = !b;
  44. }
  45. if (Input.GetMouseButtonDown(0) && ammo > 0 && ReloadTimer <= 0)
  46. {
  47. Shoot();
  48. }
  49. }
  50. else if (a == false)
  51. {
  52. maincamera.gameObject.SetActive(true);
  53. camerag.gameObject.SetActive(false);
  54. b = false;
  55. }
  56. if (Input.GetButtonDown("Reload Weapon") && Clip > 0)
  57. {
  58. ReloadTimer = 1.0f;
  59. Clip -= 1;
  60. ammo = 30;
  61. GetComponent<AudioSource>().PlayOneShot(Reload);
  62. }
  63. if (Clip > MaxClip)
  64. {
  65. Clip = MaxClip;
  66. }
  67. if (Input.GetButtonDown("Discharge Weapon"))
  68. {
  69. ammo = 0;
  70. GetComponent<AudioSource>().PlayOneShot(Discharge);
  71. }
  72. if (ReloadTimer > 0.0f)
  73. {
  74. ReloadTimer -= Time.deltaTime;
  75. }
  76. }
  77. void Shoot()
  78. {
  79. Transform BulletInstance = (Transform)Instantiate(bullet, GameObject.Find("BulletSpawnPoint").transform.position, Quaternion.identity);
  80. BulletInstance.GetComponent<Rigidbody>().AddForce(transform.forward * BulletForce);
  81. ammo -= 1;
  82. GetComponent<AudioSource>().PlayOneShot(Fire);
  83. }
  84. void OnGUI()
  85. {
  86. GUI.skin = MySkin;
  87. GUI.Box(new Rect(Screen.width - AmmoBoxWidth, 0, AmmoBoxWidth, AmmoBoxHeight), "Патронов: " + ammo + "/" + MaxAmmoCount);
  88. GUI.Label(new Rect(Screen.width - AmmoBoxWidth, 0, AmmoBoxWidth, AmmoBoxHeight), "Обойм: " + Clip + "/" + MaxClip);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement