Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class NexusSkillManager : MonoBehaviour {
- public GameObject shield;
- public List<Skill> skills;
- private GameMaster gm;
- private GameObject nexus;
- void Start()
- {
- gm = FindObjectOfType<GameMaster>();
- nexus = GameObject.FindGameObjectWithTag("Nexus");
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Alpha1) && skills[0].currentCoolDown >= skills[0].cooldown)
- {
- skills[0].currentCoolDown = 0;
- skills[0].isClick = true;
- StartCoroutine("useSkill", 5);
- }
- if (Input.GetKeyDown(KeyCode.Alpha2) && skills[1].currentCoolDown >= skills[1].cooldown)
- {
- skills[1].currentCoolDown = 0;
- skills[1].isClick = true;
- StartCoroutine("useSkill", 3);
- }
- if (Input.GetKeyDown(KeyCode.Alpha3) && skills[2].currentCoolDown >= skills[2].cooldown)
- {
- skills[2].currentCoolDown = 0;
- skills[2].isClick = true;
- StartCoroutine("useSkill", 0);
- }
- foreach(Skill s in skills)
- {
- if(s.currentCoolDown < s.cooldown)
- {
- s.currentCoolDown += Time.deltaTime;
- s.skillIcon.fillAmount = s.currentCoolDown / s.cooldown;
- }
- }
- }
- public IEnumerator useSkill(float sec)
- {
- if (skills[0].isClick) //Shield Skill
- {
- shield.SetActive(true);
- nexus.GetComponent<BoxCollider2D>().enabled = false;
- yield return new WaitForSeconds(sec);
- shield.SetActive(false);
- nexus.GetComponent<BoxCollider2D>().enabled = true;
- skills[0].isClick = false;
- }
- if (skills[1].isClick) //Slowmotion Skill
- {
- Time.timeScale = 0.3f;
- gm.GetComponent<AudioSource>().pitch = 0.8f;
- yield return new WaitForSeconds(sec);
- gm.GetComponent<AudioSource>().pitch = 1f;
- Time.timeScale = 1f;
- skills[1].isClick = false;
- }
- if (skills[2].isClick)
- {
- nexus.GetComponent<NexusMaster>().curHP += 20;
- }
- }
- }
- [System.Serializable]
- public class Skill
- {
- public float cooldown;
- public bool isClick;
- public Image skillIcon;
- [HideInInspector]
- public float currentCoolDown;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement