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 Fireball_Script : MonoBehaviour {
- public GameObject fireball, playerCamera;
- GameObject projectile;
- Fireball_Script2 script;
- bool activate, timer, zoomOut;
- public float cooldown, zoomOutCD, manaCost;
- float cooldownCopy, zoomOutCDCopy;
- newPlayerMovement playerScript;
- SkillCamera skillCam;
- Resource resource;
- void Start () {
- activate = true;
- cooldownCopy = cooldown;
- timer = false;
- playerScript = gameObject.GetComponent<newPlayerMovement>();
- skillCam = playerCamera.GetComponent<SkillCamera>();
- zoomOutCDCopy = zoomOutCD;
- zoomOut = true;
- resource = transform.gameObject.GetComponent<Resource>();
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown(KeyCode.Q) && activate && playerScript.ZStateStatus() && skillCam.CheckZoomOut() && resource.GetMana() >= manaCost)
- {
- resource.LoseMana(manaCost);
- projectile = Instantiate(fireball, transform);
- script = projectile.GetComponent<Fireball_Script2>();
- projectile.SetActive(true);
- activate = false;
- playerScript.DisableSwitchState();
- }
- }
- void FixedUpdate()
- {
- if (script != null)
- {
- if (script.CheckMaxGrow() && script.IsNew())
- {
- skillCam.SetZoom(true);
- }
- if (script.GetTravel() && !activate && script.IsNew())
- {
- timer = true;
- playerScript.EnableSwitchState();
- }
- if (script.GetTravel() && script.IsNew() && !zoomOut)
- {
- zoomOut = true;
- }
- }
- if (zoomOut)
- {
- zoomOutCD -= Time.deltaTime;
- }
- if (timer)
- {
- cooldown -= Time.deltaTime;
- }
- if (cooldown <= 0)
- {
- activate = true;
- timer = false;
- cooldown = cooldownCopy;
- }
- if (zoomOutCD <= 0)
- {
- zoomOut = false;
- skillCam.SetZoom(false);
- zoomOutCD = zoomOutCDCopy;
- }
- }
- public SkillCamera SkillCam()
- {
- return skillCam;
- }
- }
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Fireball_Script2 : MonoBehaviour {
- float grow, distance, endGrow, secondsPassed, explosion, secondsPassed2;
- public float growSpeed, maxGrow, speed, maxRange, maxEndGrow, growDecay, duration, minDistance, DPS;
- public GameObject placeholder, aimer, enemyOverhead, canvas;
- bool travel, move, shrink, isNew, tickDamage, checkForEnemy;
- public AnimationCurve anim, disappear;
- Material material;
- float[] startingDistance, countSeconds;
- Renderer render;
- Resource resource;
- SkillCamera skillCam;
- AimScript aimscript;
- FireballBurn fb;
- EnemyPatrol ePatrol;
- EnemyDetector detector;
- public GameObject managingOverhead;
- ManagingOverhead enemyOHM;
- // Use this for initialization
- void Start () {
- grow = .1f;
- travel = false;
- startingDistance = new float[3];
- distance = 0;
- move = true;
- shrink = true;
- render = gameObject.GetComponent<Renderer>();
- isNew = true;
- skillCam = placeholder.transform.Find("Camera").GetComponent<SkillCamera>();
- material = render.material;
- secondsPassed2 = 1;
- aimscript = aimer.GetComponent<AimScript>();
- tickDamage = true;
- checkForEnemy = false;
- enemyOHM = managingOverhead.GetComponent<ManagingOverhead>();
- }
- // Update is called once per frame
- private void Update()
- {
- if (Input.GetMouseButtonDown(0) && !travel && grow >= maxGrow && skillCam.CheckZoomIn() && aimscript.HitStatus(minDistance))
- {
- transform.LookAt(aimer.transform);
- transform.parent = null;
- travel = true;
- secondsPassed = 0;
- }
- }
- void FixedUpdate()
- {
- if (grow < maxGrow && move)
- {
- grow += growSpeed * Time.deltaTime;
- }
- else if (grow >= maxGrow && move)
- {
- grow = maxGrow;
- }
- transform.localScale = new Vector3(grow, grow, grow);
- if (travel && move)
- {
- transform.position += transform.forward * speed * Time.deltaTime;
- }
- if (!travel)
- {
- startingDistance = new float[] { transform.position.x, transform.position.y, transform.position.z };
- }
- 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));
- if (distance > maxRange)
- {
- move = false;
- }
- if (distance >= 1)
- {
- isNew = false;
- }
- if (!move)
- {
- if (grow > 0 && shrink)
- {
- grow -= growDecay * Time.deltaTime;
- }
- if (grow <= 0)
- {
- shrink = false;
- }
- if (!shrink)
- {
- secondsPassed += Time.deltaTime;
- grow = maxEndGrow * anim.Evaluate(secondsPassed);
- }
- if (secondsPassed >= duration - 1)
- {
- secondsPassed2 -= Time.deltaTime;
- material.color = new Color(1, 0, .09f, .66f * disappear.Evaluate(secondsPassed2));
- }
- if (secondsPassed >= duration)
- {
- Destroy(gameObject);
- }
- }
- }
- public bool GetTravel()
- {
- return travel;
- }
- private void OnTriggerEnter(Collider other)
- {
- if (travel)
- {
- if (other.gameObject.tag != "Player")
- {
- move = false;
- }
- if (other.gameObject.tag == "Enviornment")
- {
- move = false;
- }
- if (other.gameObject.tag == "Enemy")
- {
- resource = other.gameObject.GetComponent<Resource>();
- if (resource != null)
- {
- if (tickDamage && shrink)
- {
- enemyOHM.ChangeChosenEnemy(other.gameObject);
- resource.LoseHealth(50);
- tickDamage = false;
- ePatrol = other.GetComponent<EnemyPatrol>();
- if (ePatrol != null)
- {
- ePatrol.IsTakingDamage();
- }
- }
- detector = other.gameObject.GetComponent<EnemyDetector>();
- if (other.gameObject.GetComponent<EnemyDetector>())
- {
- detector.AddCollision();
- }
- FireballBurn[] i = other.gameObject.GetComponents<FireballBurn>();
- if (detector != null)
- {
- if (!other.gameObject.GetComponent<FireballBurn>() || detector.GetCollisions() > i.Length)
- {
- fb = other.gameObject.AddComponent<FireballBurn>();
- fb.OriginalFireball(gameObject);
- }
- }
- }
- }
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (travel)
- {
- if (other.gameObject.GetComponent<FireballBurn>())
- {
- Destroy(fb);
- }
- }
- }
- public bool IsNew()
- {
- return isNew;
- }
- public bool CheckMaxGrow()
- {
- if (grow == maxGrow)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement