Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class NexusSkillManager : MonoBehaviour {
  7.  
  8.  
  9.  
  10. public GameObject shield;
  11.  
  12. public List<Skill> skills;
  13.  
  14. private GameMaster gm;
  15. private GameObject nexus;
  16.  
  17. void Start()
  18. {
  19. gm = FindObjectOfType<GameMaster>();
  20. nexus = GameObject.FindGameObjectWithTag("Nexus");
  21. }
  22.  
  23. void Update()
  24. {
  25. if (Input.GetKeyDown(KeyCode.Alpha1) && skills[0].currentCoolDown >= skills[0].cooldown)
  26. {
  27. skills[0].currentCoolDown = 0;
  28. skills[0].isClick = true;
  29.  
  30. StartCoroutine("useSkill", 5);
  31. }
  32.  
  33. if (Input.GetKeyDown(KeyCode.Alpha2) && skills[1].currentCoolDown >= skills[1].cooldown)
  34. {
  35. skills[1].currentCoolDown = 0;
  36. skills[1].isClick = true;
  37.  
  38. StartCoroutine("useSkill", 3);
  39. }
  40.  
  41. if (Input.GetKeyDown(KeyCode.Alpha3) && skills[2].currentCoolDown >= skills[2].cooldown)
  42. {
  43. skills[2].currentCoolDown = 0;
  44. skills[2].isClick = true;
  45.  
  46. StartCoroutine("useSkill", 0);
  47. }
  48.  
  49.  
  50. foreach(Skill s in skills)
  51. {
  52. if(s.currentCoolDown < s.cooldown)
  53. {
  54. s.currentCoolDown += Time.deltaTime;
  55. s.skillIcon.fillAmount = s.currentCoolDown / s.cooldown;
  56. }
  57. }
  58.  
  59. }
  60.  
  61.  
  62. public IEnumerator useSkill(float sec)
  63. {
  64. if (skills[0].isClick) //Shield Skill
  65. {
  66. shield.SetActive(true);
  67. nexus.GetComponent<BoxCollider2D>().enabled = false;
  68.  
  69. yield return new WaitForSeconds(sec);
  70.  
  71. shield.SetActive(false);
  72. nexus.GetComponent<BoxCollider2D>().enabled = true;
  73.  
  74. skills[0].isClick = false;
  75. }
  76.  
  77. if (skills[1].isClick) //Slowmotion Skill
  78. {
  79. Time.timeScale = 0.3f;
  80. gm.GetComponent<AudioSource>().pitch = 0.8f;
  81.  
  82. yield return new WaitForSeconds(sec);
  83.  
  84. gm.GetComponent<AudioSource>().pitch = 1f;
  85. Time.timeScale = 1f;
  86. skills[1].isClick = false;
  87. }
  88.  
  89. if (skills[2].isClick)
  90. {
  91. nexus.GetComponent<NexusMaster>().curHP += 20;
  92. }
  93. }
  94.  
  95. }
  96.  
  97.  
  98.  
  99.  
  100. [System.Serializable]
  101. public class Skill
  102. {
  103. public float cooldown;
  104. public bool isClick;
  105. public Image skillIcon;
  106.  
  107. [HideInInspector]
  108. public float currentCoolDown;
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement