You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. public class menuContrller : MonoBehaviour {
  5. public GameObject menu;
  6. public GameObject options;
  7. public GameObject levelSelect;
  8. public GameObject instructions;
  9. public GameObject xboxLayout;
  10. public GameObject btn_1player;
  11. public GameObject btn_2player;
  12. public GameObject btn_3player;
  13. public GameObject btn_4player;
  14. public GameObject txt_score;
  15. public GameObject txt_confetti;
  16. public levelController control;
  17. public GameObject alpaca;
  18. public GameObject platypuss;
  19. public GameObject goat;
  20. public GameObject kangaroo;
  21. private bool p1Enabled = false;
  22. private bool p2Enabled = false;
  23. private bool p3Enabled = false;
  24. private bool p4Enabled = false;
  25. // Use this for initialization
  26. void Start () {
  27. control = GameObject.FindGameObjectWithTag ("GameController").GetComponent<levelController> ();
  28. }
  29. // Update is called once per frame
  30. void Update () {
  31. if (Input.GetAxisRaw ("Vertical_P1") == 1) {
  32. Debug.Log("button hit");
  33. p1Enabled = true;
  34. btn_1player.GetComponent<Image> ().color = Color.green;
  35. }
  36. if (Input.GetAxisRaw ("Vertical_P2") == 1) {
  37. p2Enabled = true;
  38. btn_2player.GetComponent<Image> ().color = Color.green;
  39. }
  40. if (Input.GetAxisRaw ("Vertical_P3") == 1) {
  41. p3Enabled = true;
  42. btn_3player.GetComponent<Image> ().color = Color.green;
  43. }
  44. if (Input.GetAxisRaw ("Vertical_P4") == 1) {
  45. p4Enabled = true;
  46. btn_4player.GetComponent<Image> ().color = Color.green;
  47. }
  48. if (Input.GetButtonDown ("start") && menu.activeSelf)
  49. panelSelect ("levelSelect");
  50. if (Input.GetButtonDown ("start") && levelSelect.activeSelf) {
  51. int tempRand = Mathf.RoundToInt(Random.Range (1,3));
  52. if (tempRand == 2)
  53. levelStart("Level1");
  54. else
  55. levelStart("Level2");
  56. }
  57. }
  58. public void panelSelect (string panel){
  59. btn_1player.GetComponent<Image> ().color = Color.grey;
  60. btn_2player.GetComponent<Image> ().color = Color.grey;
  61. btn_3player.GetComponent<Image> ().color = Color.grey;
  62. btn_4player.GetComponent<Image> ().color = Color.grey;
  63. p1Enabled = false;
  64. p2Enabled = false;
  65. p3Enabled = false;
  66. p4Enabled = false;
  67. menu.SetActive (false);
  68. options.SetActive (false);
  69. levelSelect.SetActive (false);
  70. instructions.SetActive (false);
  71. xboxLayout.SetActive (false);
  72. alpaca.SetActive (true);
  73. goat.SetActive (true);
  74. platypuss.SetActive (true);
  75. kangaroo.SetActive (true);
  76. if (panel == "menu")
  77. menu.SetActive (true);
  78. if (panel =="options")
  79. options.SetActive (true);
  80. if (panel == "levelSelect") {
  81. levelSelect.SetActive (true);
  82. alpaca.SetActive (false);
  83. goat.SetActive (false);
  84. platypuss.SetActive (false);
  85. kangaroo.SetActive (false);
  86. }
  87. if (panel == "instructions") {
  88. instructions.SetActive (true);
  89. alpaca.SetActive (false);
  90. goat.SetActive (false);
  91. platypuss.SetActive (false);
  92. kangaroo.SetActive (false);
  93. }
  94. if (panel == "xboxLayout") {
  95. xboxLayout.SetActive (true);
  96. alpaca.SetActive (false);
  97. goat.SetActive (false);
  98. platypuss.SetActive (false);
  99. kangaroo.SetActive (false);
  100. }
  101. }
  102. public void playerSelect (int players){
  103. control.playerCount = players;
  104. if (players == 1) {
  105. btn_1player.GetComponent<Image> ().color = Color.green;
  106. p1Enabled = true;
  107. }
  108. if (players == 2) {
  109. btn_2player.GetComponent<Image> ().color = Color.green;
  110. p2Enabled = true;
  111. }
  112. if (players == 3) {
  113. btn_3player.GetComponent<Image> ().color = Color.green;
  114. p3Enabled = true;
  115. }
  116. if (players == 4) {
  117. btn_4player.GetComponent<Image> ().color = Color.green;
  118. p4Enabled = true;
  119. }
  120. }
  121. public void levelStart (string level){
  122. control.p1Enabled = p1Enabled;
  123. control.p2Enabled = p2Enabled;
  124. control.p3Enabled = p3Enabled;
  125. control.p4Enabled = p4Enabled;
  126. if (p1Enabled || p2Enabled || p3Enabled || p4Enabled)
  127. Application.LoadLevel (level);
  128. }
  129. public void scoreChange (float score){
  130. txt_score.GetComponent<Text> ().text = "" + Mathf.RoundToInt(score);
  131. control.maxScore = Mathf.RoundToInt (score);
  132. }
  133. public void confettiSlider (float confetti){
  134. txt_confetti.GetComponent<Text> ().text = "" + Mathf.RoundToInt(confetti);
  135. control.confetti = Mathf.RoundToInt (confetti);
  136. }
  137. public void exit(){
  138. Application.Quit ();
  139. }
  140. }