Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Fire : MonoBehaviour {
- public ParticleSystem shoot;
- public bool isPlaying;
- public bool isReloading;
- public bool canShoot;
- public GameObject playerRotate;
- public float defaultSpriteAngle = 0;
- //this is for using objects as the projectiles
- public GameObject shot;
- public GameObject player;
- public int force = 1000;
- private int ammo;
- void Start()
- {
- shoot.Stop();
- isPlaying = false;
- isReloading = false;
- ammo = 3;
- canShoot = true;
- }
- void Update()
- {
- if (canShoot == true)
- {
- if (Input.GetKey(KeyCode.Q))
- {
- if (ammo > 0)
- {
- attack();
- StartCoroutine(Pause());
- isPlaying = true;
- canShoot = false;
- isReloading = false;
- ammo -= 1;
- }
- }
- if (ammo <= 0)
- {
- StartCoroutine(Reload());
- isReloading = true;
- isPlaying = false;
- canShoot = false;
- }
- if (ammo > 3)
- {
- ammo = 3;
- }
- }
- }
- void attack()
- {
- GameObject clone1;
- GameObject clone2;
- GameObject clone3;
- clone1 = (Instantiate(shot, new Vector2(transform.position.x, transform.position.y), (player.transform.rotation)));
- clone2 = (Instantiate(shot, new Vector2(transform.position.x, transform.position.y), player.transform.rotation));
- clone3 = (Instantiate(shot, new Vector2(transform.position.x, transform.position.y), player.transform.rotation));
- clone1.GetComponent<Rigidbody2D>().AddForce(-transform.right * force);
- clone2.GetComponent<Rigidbody2D>().AddForce(-transform.right * force);
- clone3.GetComponent<Rigidbody2D>().AddForce(-transform.right * force);
- }
- IEnumerator Pause()
- {
- yield return new WaitForSeconds(1);
- isPlaying = false;
- canShoot = true;
- }
- IEnumerator Reload()
- {
- yield return new WaitForSeconds(3);
- ammo += 3;
- isPlaying = false;
- isReloading = false;
- canShoot = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement