Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Threading;
- public class GunFire : MonoBehaviour {
- public static int MaxLength;
- public static Color IlluminCol;
- public static int delayms;
- public float dmgmin;
- public float dmgmax;
- public static GameObject pref;
- public bool IsLaser = true;
- public AudioSource Laser;
- public AudioSource Gun;
- public int batt = 5000;
- public int bullet = 10000;
- public GUIText laserammo;
- public GUIText ammo;
- public Light explosion;
- public float Distance;
- public float TracerLength;
- public float Speed;
- public GameObject muzzle;
- public Material mat;
- Vector3 scale = new Vector3(0.025f, 0.025f, 0.025f);
- GameObject bl = GameObject.CreatePrimitive(PrimitiveType.Cube);
- //public static Blasters b = pref.GetComponent<Blasters>();
- // Use this for initialization
- public void Start () {
- explosion.intensity = 0;
- explosion.color = IlluminCol;
- MeshRenderer mr = bl.AddComponent<MeshRenderer>() as MeshRenderer;
- Transform tf = bl.AddComponent<Transform>() as Transform;
- bl.renderer.material = mat;
- bl.renderer.material.color = IlluminCol;
- if(IsLaser){
- Laser = GetComponent<AudioSource>();
- }else{
- Gun = GetComponent<AudioSource>();
- }
- }
- public void Update () {
- laserammo.text = "Batteries: " + batt;
- ammo.text = "Ammo: " + bullet;
- Vector3 StartPos = transform.position;
- if(Input.GetKeyUp(transform.name.Replace("_gunKey", ""))){
- if(IsLaser && batt != 0){
- Laser.PlayDelayed(delayms / 1000);
- batt--;
- explosion.intensity = 8;
- }
- if(!IsLaser && bullet != 0){
- Gun.PlayDelayed(delayms / 1000);
- bullet--;
- explosion.intensity = 8;
- }
- //bl.transform.localScale = scale;
- if(scale.z < TracerLength){
- scale.z += Speed * Time.deltaTime;
- }else{
- bl.transform.Translate(0, 0, Speed);
- if(Vector3.Distance(bl.transform.position, muzzle.transform.position) > Distance){
- GameObject.Destroy(bl);
- }
- }
- }
- if(explosion.intensity != 0){
- explosion.intensity -= 8.0f * Time.deltaTime;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement