Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / UI / Upgrades / ChangeInfoAttackUpgrades.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /*public class ChangeInfoAttackUpgrades : MonoBehaviour
  6. {
  7. private PlayerAttackandBlock playerAttackandBlock;
  8. private PlayerGold playerGold;
  9. private PlayerLevel playerLevel;
  10. private OpenUpgrades openUpgrades;
  11. private InfoUpgrades infoUpgrades;
  12. public Button attackUpgrade1, attackUpgrade2, attackUpgrade3, attackUpgrade4;
  13. public Button doUpgrade;
  14. public GameObject noGoldText; //player has no gold but still trys to do the upgrade
  15. public GameObject noLevelText; //player has a lower level than what is needed but still trys to do the upgrade
  16. public GameObject noGoldOrLevelText;
  17. public GameObject alreadyDidText; //player did this upgrade before but trys to do it again
  18. public GameObject upgradeDoneText; //player has gold, level and didn't do this upgrade before and does the upgrade
  19. public float showMessageCoolDownTimer = 5f;
  20. private float showMessageTimer = 0;
  21. public Text levelText;
  22. public Text goldText;
  23. public Text normalAtkText;
  24. public Text strongAtkText;
  25. private Attack attack1;
  26. private Attack attack2;
  27. private Attack attack3;
  28. private Attack attack4;
  29. public bool doUpgradeIsClicked = false;
  30. public bool attackBtn1Active = false;
  31. public bool attackBtn2Active = false;
  32. public bool attackBtn3Active = false;
  33. public bool attackBtn4Active = false;
  34. public bool attackUpgrade1Done = false;
  35. public bool attackUpgrade2Done = false;
  36. public bool attackUpgrade3Done = false;
  37. public bool attackUpgrade4Done = false;
  38. // Start is called before the first frame update
  39. void Start()
  40. {
  41. playerAttackandBlock = FindObjectOfType<PlayerAttackandBlock>();
  42. playerGold = FindObjectOfType<PlayerGold>();
  43. playerLevel = FindObjectOfType<PlayerLevel>();
  44. openUpgrades = FindObjectOfType<OpenUpgrades>();
  45. infoUpgrades = new InfoUpgrades();
  46. noGoldText.gameObject.SetActive(false);
  47. noLevelText.gameObject.SetActive(false);
  48. noGoldOrLevelText.gameObject.SetActive(false);
  49. alreadyDidText.gameObject.SetActive(false);
  50. upgradeDoneText.gameObject.SetActive(false);
  51. }
  52. // Update is called once per frame
  53. void Update()
  54. {
  55. //attackUpgrade1.onClick.AddListener(AttackBtn1Clicked);
  56. //attackUpgrade2.onClick.AddListener(AttackBtn2Clicked);
  57. //attackUpgrade3.onClick.AddListener(AttackBtn3Clicked);
  58. //attackUpgrade4.onClick.AddListener(AttackBtn4Clicked);
  59. //doUpgrade.onClick.AddListener(DoUpgradeBtnIsClicked);
  60. if (showMessageTimer <= 0)
  61. {
  62. noGoldText.gameObject.SetActive(false);
  63. noLevelText.gameObject.SetActive(false);
  64. noGoldOrLevelText.gameObject.SetActive(false);
  65. alreadyDidText.gameObject.SetActive(false);
  66. upgradeDoneText.gameObject.SetActive(false);
  67. }
  68. else
  69. {
  70. showMessageTimer -= Time.deltaTime;
  71. }
  72. }
  73. private void DoUpgradeBtnIsClicked()
  74. {
  75. doUpgradeIsClicked = true;
  76. showMessageTimer = showMessageCoolDownTimer;
  77. }
  78. private void AttackBtn1Clicked ()
  79. {
  80. //write info about the upgtrade
  81. levelText.text = "Level: " + attack1.level;
  82. goldText.text = "Gold: " + attack1.gold;
  83. normalAtkText.text = "Normal Attack: +" + attack1.natk;
  84. strongAtkText.text = "Strong Attack: +" + attack1.satk;
  85. attackBtn1Active = true;
  86. attackBtn2Active = false;
  87. attackBtn3Active = false;
  88. attackBtn4Active = false;
  89. if (playerGold.gold >= attack1.gold && playerLevel.Level >= attack1.level) //if player gold and level is more or equal than what is needed
  90. {
  91. if (doUpgradeIsClicked == true && attackUpgrade1Done == false)
  92. {
  93. playerAttackandBlock.normalPlayerAttack += attack1.natk;
  94. playerAttackandBlock.strongPlayerAttack += attack1.satk;
  95. doUpgradeIsClicked = false;
  96. attackUpgrade1Done = true;
  97. //upgradeDoneText.gameObject.SetActive(true);
  98. }
  99. }
  100. else if (playerGold.gold < attack1.gold && playerLevel.Level >= attack1.level && attackUpgrade1Done == false) //if player gold is less than what is needed, change text color
  101. {
  102. Debug.Log(noGoldText);
  103. Debug.Log(showMessageTimer);
  104. goldText.color = Color.red;
  105. if (showMessageTimer > 0)
  106. {
  107. noGoldText.gameObject.SetActive(true);
  108. }
  109. }
  110. else if (playerLevel.Level < attack1.level && playerGold.gold >= attack1.gold && attackUpgrade1Done == false) //if player level is less than what is needed, change text color
  111. {
  112. levelText.color = Color.red;
  113. if (showMessageTimer > 0)
  114. {
  115. noLevelText.gameObject.SetActive(true);
  116. Debug.Log(noLevelText);
  117. Debug.Log(showMessageTimer);
  118. }
  119. }
  120. else if (playerGold.gold < attack1.gold && playerLevel.Level < attack1.level && attackUpgrade1Done == false) //if player level and gold are less than ehat is needed, change text color
  121. {
  122. Debug.Log(noGoldOrLevelText);
  123. Debug.Log(showMessageTimer);
  124. goldText.color = Color.red;
  125. levelText.color = Color.red;
  126. if (showMessageTimer > 0)
  127. {
  128. noGoldOrLevelText.gameObject.SetActive(true);
  129. }
  130. }
  131. else if (attackUpgrade1Done == true) //if player already did this upgrade
  132. {
  133. if (showMessageTimer > 0)
  134. {
  135. alreadyDidText.gameObject.SetActive(true);
  136. Debug.Log(alreadyDidText);
  137. Debug.Log(showMessageTimer);
  138. }
  139. }
  140. }
  141. private void AttackBtn2Clicked()
  142. {
  143. //write info about the upgtrade
  144. levelText.text = "Level: " + attack2.level;
  145. goldText.text = "Gold: " + attack2.gold;
  146. normalAtkText.text = "Normal Attack: +" + attack2.natk;
  147. strongAtkText.text = "Strong Attack: +" + attack2.satk;
  148. attackBtn2Active = true;
  149. attackBtn1Active = false;
  150. attackBtn3Active = false;
  151. attackBtn4Active = false;
  152. if (playerGold.gold >= attack2.gold && playerLevel.Level >= attack2.level) //if player gold and level is more or equal than what is needed
  153. {
  154. if (doUpgradeIsClicked == true && attackUpgrade1Done == true && attackUpgrade2Done == false)
  155. {
  156. playerAttackandBlock.normalPlayerAttack += attack2.natk;
  157. playerAttackandBlock.strongPlayerAttack += attack2.satk;
  158. doUpgradeIsClicked = false;
  159. attackUpgrade2Done = true;
  160. }
  161. }
  162. if (playerGold.gold < attack2.gold && playerLevel.Level >= attack2.level) //if player gold is less than what is needed, change text color
  163. {
  164. goldText.color = Color.red;
  165. if (showMessageTimer > 0)
  166. {
  167. noGoldText.gameObject.SetActive(true);
  168. showMessageTimer -= Time.deltaTime;
  169. }
  170. }
  171. else if (playerLevel.Level < attack2.level && playerGold.gold >= attack2.gold && attackUpgrade2Done == false) //if player level is less than what is needed, change text color
  172. {
  173. levelText.color = Color.red;
  174. if (showMessageTimer > 0)
  175. {
  176. noLevelText.gameObject.SetActive(true);
  177. showMessageTimer -= Time.deltaTime;
  178. }
  179. }
  180. else if (playerGold.gold < attack2.gold && playerLevel.Level < attack2.level && attackUpgrade2Done == false) //if player level and gold are less than ehat is needed, change text color
  181. {
  182. goldText.color = Color.red;
  183. levelText.color = Color.red;
  184. if (showMessageTimer > 0)
  185. {
  186. noLevelText.gameObject.SetActive(true);
  187. showMessageTimer -= Time.deltaTime;
  188. }
  189. }
  190. else if (attackUpgrade2Done == true) //if player already did this upgrade
  191. {
  192. if (showMessageTimer > 0)
  193. {
  194. alreadyDidText.gameObject.SetActive(true);
  195. showMessageTimer -= Time.deltaTime;
  196. }
  197. }
  198. }
  199. private void AttackBtn3Clicked()
  200. {
  201. //write info about the upgtrade
  202. levelText.text = "Level: " + attack3.level;
  203. goldText.text = "Gold: " + attack3.gold;
  204. normalAtkText.text = "Normal Attack: +" + attack3.natk;
  205. strongAtkText.text = "Strong Attack: +" + attack3.satk;
  206. attackBtn3Active = true;
  207. if (playerGold.gold >= attack3.gold && playerLevel.Level >= attack3.level) //if player gold and level is more or equal than what is needed
  208. {
  209. if (doUpgradeIsClicked == true && attackUpgrade2Done == true && attackUpgrade3Done == false)
  210. {
  211. playerAttackandBlock.normalPlayerAttack += attack3.natk;
  212. playerAttackandBlock.strongPlayerAttack += attack3.satk;
  213. doUpgradeIsClicked = false;
  214. attackUpgrade3Done = true;
  215. }
  216. }
  217. if (playerGold.gold < attack3.gold && playerLevel.Level >= attack3.level) //if player gold is less than what is needed, change text color
  218. {
  219. goldText.color = Color.red;
  220. if (showMessageTimer > 0)
  221. {
  222. noGoldText.gameObject.SetActive(true);
  223. showMessageTimer -= Time.deltaTime;
  224. }
  225. }
  226. else if (playerLevel.Level < attack3.level && playerGold.gold >= attack3.gold && attackUpgrade3Done == false) //if player level is less than what is needed, change text color
  227. {
  228. levelText.color = Color.red;
  229. if (showMessageTimer > 0)
  230. {
  231. noLevelText.gameObject.SetActive(true);
  232. showMessageTimer -= Time.deltaTime;
  233. }
  234. }
  235. else if (playerGold.gold < attack3.gold && playerLevel.Level < attack3.level && attackUpgrade3Done == false) //if player level and gold are less than ehat is needed, change text color
  236. {
  237. goldText.color = Color.red;
  238. levelText.color = Color.red;
  239. if (showMessageTimer > 0)
  240. {
  241. noLevelText.gameObject.SetActive(true);
  242. showMessageTimer -= Time.deltaTime;
  243. }
  244. }
  245. else if (attackUpgrade3Done == true) //if player already did this upgrade
  246. {
  247. if (showMessageTimer > 0)
  248. {
  249. alreadyDidText.gameObject.SetActive(true);
  250. showMessageTimer -= Time.deltaTime;
  251. }
  252. }
  253. }
  254. private void AttackBtn4Clicked()
  255. {
  256. //write info about the upgtrade
  257. levelText.text = "Level: " + attack4.level;
  258. goldText.text = "Gold: " + attack4.gold;
  259. normalAtkText.text = "Normal Attack: +" + attack4.natk;
  260. strongAtkText.text = "Strong Attack: +" + attack4.satk;
  261. attackBtn4Active = true;
  262. if (playerGold.gold >= attack4.gold && playerLevel.Level >= attack4.level) //if player gold and level is more or equal than what is needed
  263. {
  264. if (doUpgradeIsClicked == true && attackUpgrade3Done == true && attackUpgrade4Done == false)
  265. {
  266. playerAttackandBlock.normalPlayerAttack += attack4.natk;
  267. playerAttackandBlock.strongPlayerAttack += attack4.satk;
  268. doUpgradeIsClicked = false;
  269. attackUpgrade4Done = true;
  270. }
  271. }
  272. if (playerGold.gold < attack4.gold && playerLevel.Level >= attack4.level) //if player gold is less than what is needed, change text color
  273. {
  274. goldText.color = Color.red;
  275. if (showMessageTimer > 0)
  276. {
  277. noGoldText.gameObject.SetActive(true);
  278. showMessageTimer -= Time.deltaTime;
  279. }
  280. }
  281. else if (playerLevel.Level < attack4.level && playerGold.gold >= attack4.gold && attackUpgrade4Done == false) //if player level is less than what is needed, change text color
  282. {
  283. levelText.color = Color.red;
  284. if (showMessageTimer > 0)
  285. {
  286. noLevelText.gameObject.SetActive(true);
  287. showMessageTimer -= Time.deltaTime;
  288. }
  289. }
  290. else if (playerGold.gold < attack4.gold && playerLevel.Level < attack4.level && attackUpgrade4Done == false) //if player level and gold are less than ehat is needed, change text color
  291. {
  292. goldText.color = Color.red;
  293. levelText.color = Color.red;
  294. if (showMessageTimer > 0)
  295. {
  296. noLevelText.gameObject.SetActive(true);
  297. showMessageTimer -= Time.deltaTime;
  298. }
  299. }
  300. else if (attackUpgrade1Done == true) //if player already did this upgrade
  301. {
  302. if (showMessageTimer > 0)
  303. {
  304. alreadyDidText.gameObject.SetActive(true);
  305. showMessageTimer -= Time.deltaTime;
  306. }
  307. }
  308. }
  309. }*/