Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Fireball_Script : MonoBehaviour {
  6.  
  7.     public GameObject fireball, playerCamera;
  8.     GameObject projectile;
  9.     Fireball_Script2 script;
  10.     bool activate, timer, zoomOut;
  11.     public float cooldown, zoomOutCD, manaCost;
  12.     float cooldownCopy, zoomOutCDCopy;
  13.     newPlayerMovement playerScript;
  14.     SkillCamera skillCam;
  15.     Resource resource;
  16.  
  17.     void Start () {
  18.         activate = true;
  19.         cooldownCopy = cooldown;
  20.         timer = false;
  21.         playerScript = gameObject.GetComponent<newPlayerMovement>();
  22.         skillCam = playerCamera.GetComponent<SkillCamera>();
  23.         zoomOutCDCopy = zoomOutCD;
  24.         zoomOut = true;
  25.         resource = transform.gameObject.GetComponent<Resource>();
  26.     }
  27.    
  28.     // Update is called once per frame
  29.     void Update () {
  30.         if (Input.GetKeyDown(KeyCode.Q) && activate && playerScript.ZStateStatus() && skillCam.CheckZoomOut() && resource.GetMana() >= manaCost)
  31.         {
  32.             resource.LoseMana(manaCost);
  33.             projectile = Instantiate(fireball, transform);
  34.             script = projectile.GetComponent<Fireball_Script2>();
  35.             projectile.SetActive(true);
  36.             activate = false;
  37.             playerScript.DisableSwitchState();
  38.         }
  39.     }
  40.     void FixedUpdate()
  41.     {
  42.         if (script != null)
  43.         {
  44.             if (script.CheckMaxGrow() && script.IsNew())
  45.             {
  46.                 skillCam.SetZoom(true);
  47.             }
  48.  
  49.             if (script.GetTravel() && !activate && script.IsNew())
  50.             {
  51.                 timer = true;
  52.                 playerScript.EnableSwitchState();
  53.             }
  54.  
  55.             if (script.GetTravel() && script.IsNew() && !zoomOut)
  56.             {
  57.                 zoomOut = true;
  58.             }
  59.         }
  60.  
  61.         if (zoomOut)
  62.         {
  63.             zoomOutCD -= Time.deltaTime;
  64.         }
  65.  
  66.         if (timer)
  67.         {
  68.             cooldown -= Time.deltaTime;
  69.         }
  70.  
  71.         if (cooldown <= 0)
  72.         {
  73.             activate = true;
  74.             timer = false;
  75.             cooldown = cooldownCopy;
  76.         }
  77.  
  78.         if (zoomOutCD <= 0)
  79.         {
  80.             zoomOut = false;
  81.             skillCam.SetZoom(false);
  82.             zoomOutCD = zoomOutCDCopy;
  83.         }
  84.     }
  85.  
  86.     public SkillCamera SkillCam()
  87.     {
  88.         return skillCam;
  89.     }
  90. }
  91.  
  92. using System;
  93. using System.Collections;
  94. using System.Collections.Generic;
  95. using UnityEngine;
  96. using UnityEngine.UI;
  97.  
  98. public class Fireball_Script2 : MonoBehaviour {
  99.     float grow, distance, endGrow, secondsPassed, explosion, secondsPassed2;
  100.     public float growSpeed, maxGrow, speed, maxRange, maxEndGrow, growDecay, duration, minDistance, DPS;
  101.     public GameObject placeholder, aimer, enemyOverhead, canvas;
  102.     bool travel, move, shrink, isNew, tickDamage, checkForEnemy;
  103.     public AnimationCurve anim, disappear;
  104.     Material material;
  105.     float[] startingDistance, countSeconds;
  106.     Renderer render;
  107.     Resource resource;
  108.     SkillCamera skillCam;
  109.     AimScript aimscript;
  110.     FireballBurn fb;
  111.     EnemyPatrol ePatrol;
  112.     EnemyDetector detector;
  113.     public GameObject managingOverhead;
  114.     ManagingOverhead enemyOHM;
  115.  
  116.     // Use this for initialization
  117.     void Start () {
  118.         grow = .1f;
  119.         travel = false;
  120.         startingDistance = new float[3];
  121.         distance = 0;
  122.         move = true;
  123.         shrink = true;
  124.         render = gameObject.GetComponent<Renderer>();
  125.         isNew = true;
  126.         skillCam = placeholder.transform.Find("Camera").GetComponent<SkillCamera>();
  127.         material = render.material;
  128.         secondsPassed2 = 1;
  129.         aimscript = aimer.GetComponent<AimScript>();
  130.         tickDamage = true;
  131.         checkForEnemy = false;
  132.         enemyOHM = managingOverhead.GetComponent<ManagingOverhead>();
  133.     }
  134.  
  135.     // Update is called once per frame
  136.  
  137.     private void Update()
  138.     {
  139.         if (Input.GetMouseButtonDown(0) && !travel && grow >= maxGrow && skillCam.CheckZoomIn() && aimscript.HitStatus(minDistance))
  140.         {
  141.             transform.LookAt(aimer.transform);
  142.             transform.parent = null;
  143.             travel = true;
  144.             secondsPassed = 0;
  145.         }
  146.     }
  147.     void FixedUpdate()
  148.     {
  149.         if (grow < maxGrow && move)
  150.         {
  151.             grow += growSpeed * Time.deltaTime;
  152.         }
  153.         else if (grow >= maxGrow && move)
  154.         {
  155.             grow = maxGrow;
  156.         }
  157.  
  158.         transform.localScale = new Vector3(grow, grow, grow);
  159.  
  160.         if (travel && move)
  161.         {
  162.             transform.position += transform.forward * speed * Time.deltaTime;
  163.         }
  164.  
  165.         if (!travel)
  166.         {
  167.             startingDistance = new float[] { transform.position.x, transform.position.y, transform.position.z };
  168.         }
  169.  
  170.         distance = Mathf.Sqrt(Mathf.Pow(transform.position.x - startingDistance[0], 2) + Mathf.Pow(transform.position.y - startingDistance[1], 2) + Mathf.Pow(transform.position.z - startingDistance[2], 2));
  171.  
  172.         if (distance > maxRange)
  173.         {
  174.             move = false;
  175.         }
  176.  
  177.         if (distance >= 1)
  178.         {
  179.             isNew = false;
  180.         }
  181.  
  182.         if (!move)
  183.         {
  184.             if (grow > 0 && shrink)
  185.             {
  186.                 grow -= growDecay * Time.deltaTime;
  187.             }
  188.  
  189.             if (grow <= 0)
  190.             {
  191.                 shrink = false;
  192.             }
  193.  
  194.             if (!shrink)
  195.             {
  196.                 secondsPassed += Time.deltaTime;
  197.                 grow = maxEndGrow * anim.Evaluate(secondsPassed);
  198.             }
  199.  
  200.             if (secondsPassed >= duration - 1)
  201.             {
  202.                 secondsPassed2 -= Time.deltaTime;
  203.                 material.color = new Color(1, 0, .09f, .66f * disappear.Evaluate(secondsPassed2));
  204.             }
  205.  
  206.             if (secondsPassed >= duration)
  207.             {
  208.                 Destroy(gameObject);
  209.             }
  210.         }
  211.     }
  212.  
  213.     public bool GetTravel()
  214.     {
  215.         return travel;
  216.     }
  217.  
  218.     private void OnTriggerEnter(Collider other)
  219.     {
  220.         if (travel)
  221.         {
  222.             if (other.gameObject.tag != "Player")
  223.             {
  224.                 move = false;
  225.             }
  226.             if (other.gameObject.tag == "Enviornment")
  227.             {
  228.                 move = false;
  229.             }
  230.             if (other.gameObject.tag == "Enemy")
  231.             {
  232.  
  233.                 resource = other.gameObject.GetComponent<Resource>();
  234.  
  235.                 if (resource != null)
  236.                 {
  237.                     if (tickDamage && shrink)
  238.                     {
  239.                         enemyOHM.ChangeChosenEnemy(other.gameObject);
  240.                         resource.LoseHealth(50);
  241.                         tickDamage = false;
  242.                        
  243.                          ePatrol = other.GetComponent<EnemyPatrol>();
  244.                          if (ePatrol != null)
  245.                          {
  246.                              ePatrol.IsTakingDamage();
  247.                          }
  248.                     }
  249.  
  250.                     detector = other.gameObject.GetComponent<EnemyDetector>();
  251.  
  252.                     if (other.gameObject.GetComponent<EnemyDetector>())
  253.                     {
  254.                         detector.AddCollision();
  255.                     }
  256.  
  257.                     FireballBurn[] i = other.gameObject.GetComponents<FireballBurn>();
  258.  
  259.                     if (detector != null)
  260.                     {
  261.                         if (!other.gameObject.GetComponent<FireballBurn>() || detector.GetCollisions() > i.Length)
  262.                         {
  263.                             fb = other.gameObject.AddComponent<FireballBurn>();
  264.                             fb.OriginalFireball(gameObject);
  265.                         }
  266.                     }
  267.                 }
  268.             }
  269.         }
  270.     }
  271.  
  272.     private void OnTriggerExit(Collider other)
  273.     {
  274.         if (travel)
  275.         {
  276.             if (other.gameObject.GetComponent<FireballBurn>())
  277.             {
  278.                 Destroy(fb);
  279.             }
  280.         }
  281.     }
  282.  
  283.     public bool IsNew()
  284.     {
  285.         return isNew;
  286.     }
  287.  
  288.     public bool CheckMaxGrow()
  289.     {
  290.         if (grow == maxGrow)
  291.         {
  292.             return true;
  293.         }
  294.         else
  295.         {
  296.             return false;
  297.         }
  298.     }
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement