NGUIPowerupItemScript.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEngine;
  2. using System.Collections;
  3. public class NGUIPowerupItemScript : MonoBehaviour {
  4. public int powerupUpgradeLevelMAX;
  5. public int upgradeCost;
  6. public PowerupsMainControllerCS.PowerUps powerup;
  7. private InGameScriptCS hInGameScriptCS;
  8. private NGUIMenuScript hNGUIMenuScript;
  9. private PowerupsMainControllerCS hPowerupsMainControllerCS;
  10. private int currentPowerupLevel;
  11. private UILabel uilLevelText;
  12. private UILabel uilUpgradeCost;
  13. void Start ()
  14. {
  15. uilLevelText = (UILabel)this.transform.Find("Text_ItemLevel").GetComponent(typeof(UILabel));
  16. hInGameScriptCS = (InGameScriptCS)GameObject.Find("Player").GetComponent(typeof(InGameScriptCS));
  17. hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
  18. hPowerupsMainControllerCS = (PowerupsMainControllerCS)GameObject.Find("Player").GetComponent(typeof(PowerupsMainControllerCS));
  19. /*if (upgradeCost <= 0)
  20. Debug.Log("EXCEPTION: No cost assigned to the Power-up shop element. Check the user documentation.");
  21. else if (powerupUpgradeLevelMAX <= 0)
  22. Debug.Log("EXCEPTION: Power-up upgrade level cannot be zero. Check the user documentation.");*/
  23. uilUpgradeCost = (UILabel)transform.Find("Text_Cost").GetComponent(typeof(UILabel));
  24. uilUpgradeCost.text = upgradeCost.ToString();//set the cost of the item as specified by the user
  25. currentPowerupLevel = 1;
  26. }
  27. void Update()
  28. {
  29. uilLevelText.text = Localize.Level + Finances.GetUpgradeLevel(powerup);
  30. uilUpgradeCost.text = Finances.GetUpgradePrice(powerup).ToString();
  31. }
  32. void OnClick ()
  33. {
  34. //increase the powerup level
  35. /*if (currentPowerupLevel < powerupUpgradeLevelMAX //check if the max level has not been achieved
  36. && hInGameScriptCS.getCurrencyCount() >= upgradeCost)//check if user has enough currency
  37. {
  38. currentPowerupLevel++;//increase the power-up level
  39. hInGameScriptCS.alterCurrencyCount(-upgradeCost);//deduct the cost of power-up upgrade
  40. hNGUIMenuScript.updateCurrencyOnHeader(hNGUIMenuScript.getCurrentMenu());//update the currency on the header bar
  41. //tell the power-up script to increase the duration of the power-up
  42. hPowerupsMainControllerCS.upgradePowerup(powerup);
  43. //Update the text on the power-up item in shop
  44. uilLevelText.text = "Level "+currentPowerupLevel;
  45. }*/
  46. if (Finances.Coins >= Finances.GetUpgradePrice(powerup))
  47. {
  48. Finances.Upgrade(powerup);
  49. }
  50. }//end of On Click
  51. }