Guest User

Weapon.js

a guest
Sep 28th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var bulletObject: GameObject;
  4. var canShoot: boolean;
  5. var currentClip: int;
  6. var extraAmmo: int;
  7. var canReload: boolean;
  8. var difference: int;
  9.  
  10. function Start () {
  11.  
  12. canShoot = true;
  13. currentClip = 5;
  14. extraAmmo = 20;
  15.  
  16. }
  17.  
  18. function Update () {
  19.  
  20. booleans();
  21.  
  22.  
  23. if(canReload == true){
  24.  
  25. if(Input.GetKeyDown(KeyCode.R)){
  26.  
  27.     difference = 5 - currentClip;
  28.  
  29.     currentClip += difference;
  30.    
  31.     extraAmmo -= difference;
  32.  
  33. }
  34.  
  35. }
  36.  
  37. }
  38.  
  39. function shootUp(){
  40.  
  41.     if(Input.GetButtonDown("Fire1")){
  42.    
  43.         Instantiate(bulletObject, transform.position, Quaternion.identity);
  44.         currentClip -= 1;
  45.    
  46. }
  47.  
  48.  
  49. }
  50.  
  51. function booleans(){
  52.  
  53. if(extraAmmo <= 0){
  54.  
  55.     extraAmmo = 0;
  56.  
  57. }
  58. if(extraAmmo > 0){
  59.  
  60. canReload = true;
  61.  
  62. }
  63. else{
  64.  
  65. canReload = false;
  66.  
  67. }
  68.  
  69. if(extraAmmo <= 0){
  70.  
  71.     canReload = false;
  72.  
  73. }
  74.  
  75. if(currentClip < 5){
  76.  
  77.     canReload = true;
  78.  
  79. }
  80.  
  81. if(currentClip <= 0){
  82.  
  83.     canShoot = false;
  84.    
  85. }else{
  86.  
  87.     canShoot = true;
  88.  
  89. }
  90.        
  91. if(canShoot == true){
  92.  
  93.     shootUp();
  94.  
  95. }
  96.  
  97.  
  98.  
  99.  
  100. }
  101.  
  102. function OnGUI(){
  103.  
  104. GUI.Label(Rect(10,10,200,20),"" + currentClip);
  105. GUI.Label(Rect(18,10,200,20),"/" + extraAmmo);
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment