Advertisement
Guest User

UpgradeManagerGhetto

a guest
Apr 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. private int[] hullUpgLevels = { 100, 150, 225, 325, 450 };
  2. private int[] hullUpgCost = { 0, 10, 25, 50, 100 };
  3. public static int hullLvlIndex = 0;
  4. // so that i can just reference it from saving
  5. //also these 2 things always point to the same thing so irrelevant
  6. private int hullUpgCostIndex = 0;
  7.  
  8.  
  9. [SerializeField] private GameObject[] hullBars = new GameObject[4];
  10. [SerializeField] private Image[] fuelBars = new Image[4];
  11. [SerializeField] private Image[] finsBars = new Image[4];
  12. [SerializeField] private Image[] engineBars = new Image[4];
  13.  
  14.  
  15. private void Start()
  16. {
  17.  
  18. }
  19.  
  20. //so this script talks to "playerstats" instance
  21. //lets debug to see whats up waitbe
  22. // I can delete playerstats rn and it would fine, everything is still in Player, I just put playerstats for testing purposes
  23.  
  24. //just to be sure, what this upgrade is supposed to do is change the player's max health to something larger yes?
  25.  
  26. // Increase max health
  27. public void UpgradeHull()
  28. {
  29. if (hullUpgCostIndex < hullBars.Length)
  30. {
  31. //its probably this, sec
  32. //want to check price to next element in array, but not move to it yet
  33. //post-pre fix operators assign 1 more / 1 less, doing + 1 doesn't change index value
  34. if (CurrencyManager.Currency >= hullUpgCost[hullUpgCostIndex + 1])
  35. {
  36. CurrencyManager.Currency -= hullUpgCost[++hullUpgCostIndex];
  37.  
  38. //logic error is you're having 100 as the 1st upgrade (remember 0 count)
  39. //so the first time this runs thru it evaluates 100 as the "next jump"
  40. //fix:
  41. //think about this in a general level
  42. //that would increment it beforehand, ill explain in a bit
  43. //this is talking about UPGRADES
  44. //your base level is fine to have as the 0'th upgrade
  45. //but when you upgrade, you increase it to 1 not to 0
  46. //fix:
  47. PlayerStats.Instance.maxHealth = hullUpgLevels[++hullLvlIndex];
  48.  
  49. //now the upgrade here is, we want to toggle the bar whose level we upgraded
  50. //if its an array, it plays nicely with our indices
  51. //first update is 0'th element, second update is 1st element, ...
  52.  
  53. //problem here too is that it's loading lvl X, but it will toggle lvl X - 1
  54. //need to put more thought into it
  55. hullBars[hullLvlIndex - 1].SetActive(true);
  56.  
  57.  
  58.  
  59. //reason its - 1 is because of the reason above, when we're on 1st update
  60. //its the 0'th element that we're toggling
  61. //this approach is fine, use arrays in ur favor
  62. //hullFillBar1.enabled = true;
  63. //hullUpgCostIndex++;
  64. //hullLvlIndex++;
  65. }
  66. }
  67. }
  68.  
  69. // Increase max fuel
  70. void UpgradeFuelTank()
  71. {
  72.  
  73. }
  74.  
  75. // Increase turn power
  76. void UpgradeFins()
  77. {
  78.  
  79. }
  80.  
  81. // Increase thruster speed
  82. void UpgradeEngine()
  83. {
  84.  
  85. }
  86.  
  87. public void Load()
  88. {
  89. Debug.Log("Loaded Data.");
  90. hullLvlIndex = SaveManager.LoadData().hullLvl;
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement