Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.33 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LaserManager : MonoBehaviour {
  6.  
  7.     LineRenderer laser;
  8.     bool laserStartup;
  9.     float laserEnd;
  10.     bool laserOff;
  11.     public float laserTime, laserFiringTimer, chargeTime;
  12.     public float laserTimer, chargeTimer;
  13.     public bool laserWider;
  14.     public float cameraTime;
  15.     public float cameraTimer;
  16.     public bool cameraLeft;
  17.     public GameObject model;
  18.     GameObject camera;
  19.     GameObject juanzilla;
  20.     string inputString;
  21.     GameObject switchingManager;
  22.     public GameObject shield;
  23.     public float laserLength;
  24.     public bool laserUpgradeAvailable, laserStarted;
  25.  
  26.     // Use this for initialization
  27.     void Start () {
  28.         laser = gameObject.GetComponent<LineRenderer>();
  29.         laser.enabled = false;
  30.         laserEnd = 1;
  31.         laserWider = true;
  32.         camera = GameObject.Find("Juanzilla Camera");
  33.         juanzilla = GameObject.Find("Juanzilla");
  34.         switchingManager = GameObject.Find("SwitchingManager");
  35.        
  36.     }
  37.    
  38.     // Update is called once per frame
  39.     void Update () {
  40.  
  41.         if (laserStarted)
  42.         {
  43.             laserFiringTimer += Time.deltaTime;
  44.             if (laserFiringTimer >= 1)
  45.             {
  46.                 laserFiringTimer = 0;
  47.                 laserStarted = false;
  48.                 laserUpgradeAvailable = false;
  49.             }
  50.         }
  51.  
  52.         model.GetComponent<Renderer>().material.color = new Color(1, 1, 1);
  53.  
  54.         if (chargeTimer > 0 && !(Input.GetAxis(InputManager.juanzillaR1) != 0))
  55.         {
  56.             chargeTimer = 0;
  57.  
  58.         }
  59.  
  60.         cameraTime += 1 * Time.deltaTime;
  61.         laserTime += 1 * Time.deltaTime;
  62.         if (Input.GetAxis(InputManager.juanzillaR1) != 0 && laserUpgradeAvailable)
  63.         {
  64.             chargeTimer += 1 * Time.deltaTime;
  65.             model.GetComponent<Renderer>().material.color = new Color(1 * (1 - chargeTimer),1 * (1 - chargeTimer),1f);//("BlueColor", Color.blue);
  66.             if (chargeTimer >= chargeTime)
  67.             {
  68.                 StopCoroutine("FireLaser");
  69.                 StartCoroutine("FireLaser");
  70.             }
  71.         }
  72.  
  73.         if (Input.GetAxis(InputManager.juanzillaR1) == 0)
  74.         {
  75.             laserOff = true;
  76.             laserEnd = 1;
  77.             shield.GetComponent<MechaTrumpShield>().reflectingLaser = false;
  78.         }
  79.     }
  80.  
  81.     IEnumerator FireLaser()
  82.     {
  83.         laser.enabled = true;
  84.         laserStarted = true;
  85.         if (laserOff)
  86.         {
  87.             laserStartup = true;
  88.             laserOff = false;
  89.         }
  90.  
  91.         juanzilla.transform.Translate(0, 0, -0.1f);
  92.  
  93.         while (Input.GetAxis(InputManager.juanzillaR1) != 0 && laserUpgradeAvailable)
  94.         {
  95.             laser.material.mainTextureOffset = new Vector2(-Time.time * 5.0f, 0);
  96.             if (laserTime >= laserTimer)
  97.             {
  98.                
  99.                 if (laserWider)
  100.                 {
  101.                     laser.startWidth = laser.widthMultiplier + 0.15f;
  102.                     laser.endWidth = laser.widthMultiplier + 0.15f;
  103.                     camera.transform.Translate(-0.2f, 0, 0);
  104.                 }
  105.                 else if (!laserWider)
  106.                 {
  107.                     laser.startWidth = laser.widthMultiplier - 0.15f;
  108.                     laser.endWidth = laser.widthMultiplier - 0.15f;
  109.                     camera.transform.Translate(0.2f, 0, 0);
  110.                 }
  111.                 laserWider = !laserWider;
  112.                 laserTime = 0;
  113.             }
  114.  
  115.             if (cameraTime >= cameraTimer)
  116.             {
  117.                 if (cameraLeft)
  118.                 {
  119.                     camera.transform.Translate(0, -0.2f, 0);
  120.                 }
  121.                 else if (!cameraLeft)
  122.                 {
  123.                     camera.transform.Translate(0, 0.2f, 0);
  124.                 }
  125.                 cameraLeft = !cameraLeft;
  126.                 cameraTime = 0;
  127.             }
  128.  
  129.  
  130.  
  131.             Ray ray = new Ray(transform.position, transform.forward);
  132.  
  133.             RaycastHit hit;
  134.  
  135.             laser.SetPosition(0, ray.origin);
  136.  
  137.             if (laserStartup)
  138.             {
  139.                 laserEnd += 15;
  140.                 laser.SetPosition(1, ray.GetPoint(laserEnd));
  141.  
  142.                 if (laserEnd >= 100)
  143.                 {
  144.                     laserStartup = false;
  145.                     laserEnd = 0;
  146.                 }
  147.             }
  148.            
  149.             if (Physics.Raycast(ray, out hit, 100))
  150.             {
  151.                 laser.SetPosition(1, hit.point);
  152.                 if (hit.rigidbody)
  153.                 {
  154.                    
  155.                     if (hit.rigidbody.gameObject.tag == "Building")
  156.                     {
  157.                         hit.rigidbody.gameObject.GetComponent<BuildingDestruction>().DestroyBuilding();
  158.                     }
  159.                     if (hit.rigidbody.gameObject.tag == "Wall")
  160.                     {
  161.                         hit.rigidbody.gameObject.GetComponent<MechaTrumpWall>().DestroyWall();
  162.                     }
  163.                     if (hit.rigidbody.gameObject.tag == "Shield")
  164.                     {
  165.                         shield.GetComponent<MechaTrumpShield>().DeflectLaser(hit);
  166.                     }
  167.                     if (hit.rigidbody.gameObject.tag == "Juanzilla")
  168.                     {
  169.                         hit.rigidbody.gameObject.GetComponent<HealthController>().currentHealth -= 1;
  170.                     }
  171.                     else
  172.                     {
  173.                         hit.rigidbody.AddForceAtPosition(transform.forward * 1000, hit.point);
  174.                         shield.GetComponent<MechaTrumpShield>().reflectingLaser = false;
  175.                     }
  176.                 }
  177.                
  178.             }
  179.             else if(!laserStartup)
  180.             {
  181.                 laser.SetPosition(1, ray.GetPoint(100));
  182.                 shield.GetComponent<MechaTrumpShield>().reflectingLaser = false;
  183.             }
  184.            
  185.             yield return null;
  186.         }
  187.  
  188.         laser.enabled = false;
  189.     }
  190.  
  191.     public void ToggleLineRendererActive()
  192.     {
  193.         if (gameObject.GetComponent<LineRenderer>().enabled)
  194.         {
  195.             gameObject.GetComponent<LineRenderer>().enabled = false;
  196.         }
  197.         else
  198.         {
  199.             gameObject.GetComponent<LineRenderer>().enabled = true;
  200.         }
  201.     }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement