"Firing script" By DangerousAmoeba (https://pastebin.com/u/DangerousAmoeba) URL: https://pastebin.com/epxcVPgp Created on: Sunday 7th of June 2015 02:09:51 AM CDT Retrieved on: Sunday 25 of October 2020 05:04:02 AM UTC using UnityEngine; using System.Collections; public class PistolFire : MonoBehaviour { public GameObject fireer; float firetime = 0.1f; public GameObject bullet; public Transform fireertransform; public GameObject shell; public Transform shelltransform; public int Magazine; bool reload = false; IEnumerator FireAnimation() { GetComponent().Play("PistolFire"); yield return new WaitForSeconds(firetime); GetComponent().Play("Idle"); if (reload == true) { rel(); reload = false; } } void Update() { if (Magazine > 0) { if (Input.GetButtonDown ("Fire1")) { GetComponent ().StopPlayback (); StartCoroutine (FireAnimation ()); fireer.GetComponent ().Play (); GameObject clone; clone = GameObject.Instantiate (bullet, fireertransform.position, fireertransform.rotation) as GameObject; clone.name = "boolet"; clone.GetComponent ().AddForce (transform.right * 10000); Destroy (clone, 2); shell = GameObject.Instantiate (shell, shelltransform.position, shelltransform.rotation) as GameObject; shell.name = "shell"; shell.GetComponent ().AddForce (transform.up * 300); shell.GetComponent ().AddForce (-transform.forward * 200); fireer.GetComponent ().AddForce (-transform.right * 3000); fireer.GetComponent ().AddForce (transform.up * 1000); Magazine --; if (Magazine <1) { reload = true; } } } } void rel() { GetComponent ().Play (); Magazine = (15); } }