Advertisement
EmperorDuck

Untitled

Jan 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Fire : MonoBehaviour {
  6.    
  7.     public ParticleSystem shoot;
  8.    
  9.     public bool isPlaying;
  10.     public bool isReloading;
  11.     public bool canShoot;
  12.     public GameObject playerRotate;
  13.     public float defaultSpriteAngle = 0;
  14.  
  15.     //this is for using objects as the projectiles
  16.     public GameObject shot;
  17.     public GameObject player;
  18.     public int force = 1000;
  19.  
  20.     private int ammo;
  21.    
  22.     void Start()
  23.     {        
  24.         shoot.Stop();
  25.         isPlaying = false;
  26.         isReloading = false;
  27.         ammo = 3;
  28.         canShoot = true;
  29.     }
  30.  
  31.     void Update()
  32.     {
  33.         if (canShoot == true)
  34.         {
  35.             if (Input.GetKey(KeyCode.Q))
  36.             {
  37.                 if (ammo > 0)
  38.                 {
  39.                     attack();                    
  40.                     StartCoroutine(Pause());
  41.                     isPlaying = true;
  42.                     canShoot = false;
  43.                     isReloading = false;
  44.                     ammo -= 1;
  45.                 }
  46.             }
  47.  
  48.             if (ammo <= 0)
  49.             {
  50.                     StartCoroutine(Reload());
  51.                     isReloading = true;
  52.                     isPlaying = false;
  53.                     canShoot = false;
  54.             }
  55.  
  56.             if (ammo > 3)
  57.             {
  58.                 ammo = 3;
  59.             }
  60.            
  61.         }
  62.     }
  63.  
  64.     void attack()
  65.     {
  66.         GameObject clone1;
  67.         GameObject clone2;
  68.         GameObject clone3;
  69.  
  70.         clone1 = (Instantiate(shot, new Vector2(transform.position.x, transform.position.y), (player.transform.rotation)));
  71.         clone2 = (Instantiate(shot, new Vector2(transform.position.x, transform.position.y), player.transform.rotation));
  72.         clone3 = (Instantiate(shot, new Vector2(transform.position.x, transform.position.y), player.transform.rotation));
  73.  
  74.         clone1.GetComponent<Rigidbody2D>().AddForce(-transform.right * force);
  75.         clone2.GetComponent<Rigidbody2D>().AddForce(-transform.right * force);
  76.         clone3.GetComponent<Rigidbody2D>().AddForce(-transform.right * force);
  77.     }
  78.  
  79.     IEnumerator Pause()
  80.     {
  81.         yield return new WaitForSeconds(1);
  82.         isPlaying = false;
  83.         canShoot = true;
  84.     }
  85.  
  86.     IEnumerator Reload()
  87.     {
  88.         yield return new WaitForSeconds(3);
  89.         ammo += 3;
  90.         isPlaying = false;
  91.         isReloading = false;
  92.         canShoot = true;
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement