Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. //using UnityEngine.Advertisements;
  5.  
  6.  
  7. public class GameOverlord : MonoBehaviour {
  8. public int deaths;
  9.  
  10. public int playerCurrency = 1500;
  11. public int player2Bought = 0;
  12. public int player3Bought = 0;
  13. public int player4Bought = 0;
  14.  
  15. public bool player1Selected;
  16. public bool player2Selected;
  17. public bool player3Selected;
  18. public bool player4Selected;
  19.  
  20. public Text snowflakes;
  21. public Text snowflakesBack;
  22.  
  23. public CharacterSelectManager charManager;
  24.  
  25. //Makes it so the script is not destroyed on load. The scene this script is on is loaded before the start menu.
  26. void Awake() {
  27. Screen.SetResolution(320, 480, true);
  28. playerCurrency = 1500;
  29. PlayerPrefs.SetInt("PlayerCurrency", playerCurrency);
  30. DontDestroyOnLoad(transform.gameObject);
  31. player1Selected = true;
  32. deaths = 0;
  33. }
  34.  
  35. //Stores and accesses the currency the player has and if they have bought a character or not. Preferences between game sessions.
  36. void Start(){
  37. if (PlayerPrefs.HasKey ("PlayerCurrency")) {
  38. playerCurrency = PlayerPrefs.GetInt("PlayerCurrency");
  39.  
  40. }
  41. if (PlayerPrefs.HasKey ("Player2BoughtBool")) {
  42. player2Bought = PlayerPrefs.GetInt("Player2BoughtBool");
  43.  
  44. }
  45. if (PlayerPrefs.HasKey ("Player3BoughtBool")) {
  46. player3Bought = PlayerPrefs.GetInt("Player3BoughtBool");
  47.  
  48. }
  49. if (PlayerPrefs.HasKey ("Player4BoughtBool")) {
  50. player4Bought = PlayerPrefs.GetInt("Player4BoughtBool");
  51.  
  52. }
  53. }
  54.  
  55.  
  56. void Update(){
  57. GameObject charGo = GameObject.Find("ButtonManager");
  58. charManager = charGo.GetComponent<CharacterSelectManager>();
  59.  
  60. if (player2Bought == 1)
  61. {
  62. charManager.squirrelSprite.color = Color.white;
  63. charManager.buyPlayer2Button.SetActive(false);
  64. charManager.player2SelectButton.SetActive(true);
  65. }
  66. if (player3Bought == 1)
  67. {
  68. charManager.explorerSprite.color = Color.white;
  69. charManager.buyPlayer3Button.SetActive(false);
  70. charManager.player3SelectButton.SetActive(true);
  71. }
  72. if (player4Bought == 1)
  73. {
  74. charManager.wizardSprite.color = Color.white;
  75. charManager.buyPlayer4Button.SetActive(false);
  76. charManager.player4SelectButton.SetActive(true);
  77. }
  78.  
  79. //Sets the PlayerPref int to an int that can be controlled in the script.
  80. PlayerPrefs.SetInt("PlayerCurrency", playerCurrency);
  81. PlayerPrefs.SetInt("Player2BoughtBool", player2Bought);
  82. PlayerPrefs.SetInt("Player3BoughtBool", player3Bought);
  83. PlayerPrefs.SetInt("Player4BoughtBool", player4Bought);
  84.  
  85. snowflakes = GameObject.FindGameObjectWithTag ("Currency").GetComponent<Text>();
  86. snowflakesBack = GameObject.FindGameObjectWithTag ("Currency2").GetComponent<Text>();
  87.  
  88. snowflakes.text = " " + Mathf.Round(playerCurrency);
  89. snowflakesBack.text = " " + Mathf.Round(playerCurrency);
  90.  
  91. //Calls DeathAds function
  92. DeathAds ();
  93.  
  94. }
  95.  
  96. //Brings up an Ad every 5 deaths and will add 10 currency to the player.
  97. void DeathAds(){
  98. if (deaths >= 5) {
  99. //ShowAd ();
  100. playerCurrency += 10;
  101. deaths = 0;
  102.  
  103. }
  104.  
  105.  
  106.  
  107. }
  108.  
  109. //Determines which character is selected.
  110. public void Player1Click(){
  111. player1Selected = true;
  112. player2Selected = false;
  113. player3Selected = false;
  114. player4Selected = false;
  115. }
  116.  
  117. public void Player2Click(){
  118. player2Selected = true;
  119. player1Selected = false;
  120. player3Selected = false;
  121. player4Selected = false;
  122. }
  123. public void Player3Click(){
  124. player3Selected = true;
  125. player1Selected = false;
  126. player2Selected = false;
  127. player4Selected = false;
  128.  
  129. }
  130. public void PlayerClick(){
  131. player4Selected = true;
  132. player1Selected = false;
  133. player2Selected = false;
  134. player3Selected = false;
  135.  
  136. }
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement