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 LaserManager : MonoBehaviour {
- LineRenderer laser;
- bool laserStartup;
- float laserEnd;
- bool laserOff;
- public float laserTime, laserFiringTimer, chargeTime;
- public float laserTimer, chargeTimer;
- public bool laserWider;
- public float cameraTime;
- public float cameraTimer;
- public bool cameraLeft;
- public GameObject model;
- GameObject camera;
- GameObject juanzilla;
- string inputString;
- GameObject switchingManager;
- public GameObject shield;
- public float laserLength;
- public bool laserUpgradeAvailable, laserStarted;
- // Use this for initialization
- void Start () {
- laser = gameObject.GetComponent<LineRenderer>();
- laser.enabled = false;
- laserEnd = 1;
- laserWider = true;
- camera = GameObject.Find("Juanzilla Camera");
- juanzilla = GameObject.Find("Juanzilla");
- switchingManager = GameObject.Find("SwitchingManager");
- }
- // Update is called once per frame
- void Update () {
- if (laserStarted)
- {
- laserFiringTimer += Time.deltaTime;
- if (laserFiringTimer >= 1)
- {
- laserFiringTimer = 0;
- laserStarted = false;
- laserUpgradeAvailable = false;
- }
- }
- model.GetComponent<Renderer>().material.color = new Color(1, 1, 1);
- if (chargeTimer > 0 && !(Input.GetAxis(InputManager.juanzillaR1) != 0))
- {
- chargeTimer = 0;
- }
- cameraTime += 1 * Time.deltaTime;
- laserTime += 1 * Time.deltaTime;
- if (Input.GetAxis(InputManager.juanzillaR1) != 0 && laserUpgradeAvailable)
- {
- chargeTimer += 1 * Time.deltaTime;
- model.GetComponent<Renderer>().material.color = new Color(1 * (1 - chargeTimer),1 * (1 - chargeTimer),1f);//("BlueColor", Color.blue);
- if (chargeTimer >= chargeTime)
- {
- StopCoroutine("FireLaser");
- StartCoroutine("FireLaser");
- }
- }
- if (Input.GetAxis(InputManager.juanzillaR1) == 0)
- {
- laserOff = true;
- laserEnd = 1;
- shield.GetComponent<MechaTrumpShield>().reflectingLaser = false;
- }
- }
- IEnumerator FireLaser()
- {
- laser.enabled = true;
- laserStarted = true;
- if (laserOff)
- {
- laserStartup = true;
- laserOff = false;
- }
- juanzilla.transform.Translate(0, 0, -0.1f);
- while (Input.GetAxis(InputManager.juanzillaR1) != 0 && laserUpgradeAvailable)
- {
- laser.material.mainTextureOffset = new Vector2(-Time.time * 5.0f, 0);
- if (laserTime >= laserTimer)
- {
- if (laserWider)
- {
- laser.startWidth = laser.widthMultiplier + 0.15f;
- laser.endWidth = laser.widthMultiplier + 0.15f;
- camera.transform.Translate(-0.2f, 0, 0);
- }
- else if (!laserWider)
- {
- laser.startWidth = laser.widthMultiplier - 0.15f;
- laser.endWidth = laser.widthMultiplier - 0.15f;
- camera.transform.Translate(0.2f, 0, 0);
- }
- laserWider = !laserWider;
- laserTime = 0;
- }
- if (cameraTime >= cameraTimer)
- {
- if (cameraLeft)
- {
- camera.transform.Translate(0, -0.2f, 0);
- }
- else if (!cameraLeft)
- {
- camera.transform.Translate(0, 0.2f, 0);
- }
- cameraLeft = !cameraLeft;
- cameraTime = 0;
- }
- Ray ray = new Ray(transform.position, transform.forward);
- RaycastHit hit;
- laser.SetPosition(0, ray.origin);
- if (laserStartup)
- {
- laserEnd += 15;
- laser.SetPosition(1, ray.GetPoint(laserEnd));
- if (laserEnd >= 100)
- {
- laserStartup = false;
- laserEnd = 0;
- }
- }
- if (Physics.Raycast(ray, out hit, 100))
- {
- laser.SetPosition(1, hit.point);
- if (hit.rigidbody)
- {
- if (hit.rigidbody.gameObject.tag == "Building")
- {
- hit.rigidbody.gameObject.GetComponent<BuildingDestruction>().DestroyBuilding();
- }
- if (hit.rigidbody.gameObject.tag == "Wall")
- {
- hit.rigidbody.gameObject.GetComponent<MechaTrumpWall>().DestroyWall();
- }
- if (hit.rigidbody.gameObject.tag == "Shield")
- {
- shield.GetComponent<MechaTrumpShield>().DeflectLaser(hit);
- }
- if (hit.rigidbody.gameObject.tag == "Juanzilla")
- {
- hit.rigidbody.gameObject.GetComponent<HealthController>().currentHealth -= 1;
- }
- else
- {
- hit.rigidbody.AddForceAtPosition(transform.forward * 1000, hit.point);
- shield.GetComponent<MechaTrumpShield>().reflectingLaser = false;
- }
- }
- }
- else if(!laserStartup)
- {
- laser.SetPosition(1, ray.GetPoint(100));
- shield.GetComponent<MechaTrumpShield>().reflectingLaser = false;
- }
- yield return null;
- }
- laser.enabled = false;
- }
- public void ToggleLineRendererActive()
- {
- if (gameObject.GetComponent<LineRenderer>().enabled)
- {
- gameObject.GetComponent<LineRenderer>().enabled = false;
- }
- else
- {
- gameObject.GetComponent<LineRenderer>().enabled = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement