Guest User

GunFire

a guest
Apr 14th, 2018
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Threading;
  4.  
  5. public class GunFire : MonoBehaviour {
  6.  
  7.     public static int MaxLength;
  8.     public static Color IlluminCol;
  9.     public static int delayms;
  10.     public float dmgmin;
  11.     public float dmgmax;
  12.     public static GameObject pref;
  13.     public bool IsLaser = true;
  14.     public AudioSource Laser;
  15.     public AudioSource Gun;
  16.     public int batt = 5000;
  17.     public int bullet = 10000;
  18.     public GUIText laserammo;
  19.     public GUIText ammo;
  20.     public Light explosion;
  21.     public float Distance;
  22.     public float TracerLength;
  23.     public float Speed;
  24.     public GameObject muzzle;
  25.     public Material mat;
  26.     Vector3 scale = new Vector3(0.025f, 0.025f, 0.025f);
  27.     GameObject bl = GameObject.CreatePrimitive(PrimitiveType.Cube);
  28.    
  29.     //public static Blasters b = pref.GetComponent<Blasters>();
  30.    
  31.    
  32.     // Use this for initialization
  33.     public void Start () {
  34.         explosion.intensity = 0;
  35.         explosion.color = IlluminCol;
  36.         MeshRenderer mr = bl.AddComponent<MeshRenderer>() as MeshRenderer;
  37.         Transform tf = bl.AddComponent<Transform>() as Transform;
  38.         bl.renderer.material = mat;
  39.         bl.renderer.material.color = IlluminCol;
  40.         if(IsLaser){
  41.             Laser = GetComponent<AudioSource>();
  42.         }else{
  43.             Gun = GetComponent<AudioSource>();
  44.         }
  45.     }
  46.  
  47.     public void Update () {
  48.         laserammo.text = "Batteries: " + batt;
  49.         ammo.text = "Ammo: " + bullet;
  50.         Vector3 StartPos = transform.position;
  51.         if(Input.GetKeyUp(transform.name.Replace("_gunKey", ""))){
  52.             if(IsLaser && batt != 0){
  53.                 Laser.PlayDelayed(delayms / 1000);
  54.                 batt--;
  55.                 explosion.intensity = 8;
  56.             }
  57.             if(!IsLaser && bullet != 0){
  58.                 Gun.PlayDelayed(delayms / 1000);
  59.                 bullet--;
  60.                 explosion.intensity = 8;
  61.             }
  62.             //bl.transform.localScale = scale;
  63.             if(scale.z < TracerLength){
  64.                 scale.z += Speed * Time.deltaTime;
  65.             }else{
  66.                 bl.transform.Translate(0, 0, Speed);
  67.                 if(Vector3.Distance(bl.transform.position, muzzle.transform.position) > Distance){
  68.                     GameObject.Destroy(bl);
  69.                 }
  70.             }
  71.         }
  72.         if(explosion.intensity != 0){
  73.             explosion.intensity -= 8.0f * Time.deltaTime;
  74.         }
  75.     }
  76. }
RAW Paste Data