155 lines
3.4 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. public class sceneController : MonoBehaviour {
  5. public GameObject player1;
  6. public GameObject player2;
  7. public GameObject player3;
  8. public GameObject player4;
  9. public levelController control;
  10. private int playerCount;
  11. public GameObject options;
  12. public bool paused = false;
  13. public GameObject confettiText;
  14. public GameObject scoreText;
  15. public playerId id1;
  16. public playerId id2;
  17. public playerId id3;
  18. public playerId id4;
  19. private playerController playerScript1;
  20. private playerController playerScript2;
  21. private playerController playerScript3;
  22. private playerController playerScript4;
  23. private bool exit = false;
  24. // Use this for initialization
  25. void Awake(){
  26. playerScript1 = player1.GetComponent<playerController> ();
  27. playerScript2 = player2.GetComponent<playerController> ();
  28. playerScript3 = player3.GetComponent<playerController> ();
  29. playerScript4 = player4.GetComponent<playerController> ();
  30. }
  31. void Start () {
  32. control = GameObject.FindGameObjectWithTag ("GameController").GetComponent<levelController> ();
  33. player1.SetActive (false);
  34. player2.SetActive (false);
  35. player3.SetActive (false);
  36. player4.SetActive (false);
  37. playerCount = control.playerCount;
  38. if (playerCount >= 1)
  39. player1.SetActive (true);
  40. if (playerCount >= 2)
  41. player2.SetActive (true);
  42. if (playerCount >= 3)
  43. player3.SetActive (true);
  44. if (playerCount >= 4)
  45. player4.SetActive (true);
  46. playerScript1.maxScore = control.maxScore;
  47. playerScript2.maxScore = control.maxScore;
  48. playerScript3.maxScore = control.maxScore;
  49. playerScript4.maxScore = control.maxScore;
  50. playerScript1.confettiOnHit = control.confetti;
  51. playerScript2.confettiOnHit = control.confetti;
  52. playerScript3.confettiOnHit = control.confetti;
  53. playerScript4.confettiOnHit = control.confetti;
  54. }
  55. // Update is called once per frame
  56. void Update () {
  57. if (Input.GetButtonDown("start")) {
  58. paused = !paused;
  59. }
  60. optionsSelect ();
  61. }
  62. public void optionsSelect(){
  63. if (paused) {
  64. Time.timeScale = 0.0f;
  65. options.SetActive (true);
  66. } else if (!paused) {
  67. Time.timeScale = 1.0f;
  68. options.SetActive (false);
  69. }
  70. if (exit) {
  71. Time.timeScale = 1.0f;
  72. Application.LoadLevel("Menu_Scene");
  73. }
  74. }
  75. public void confetti(float confettiAmount){
  76. control.confetti = Mathf.RoundToInt(confettiAmount);
  77. confettiText.GetComponent<Text> ().text = "" + Mathf.RoundToInt(confettiAmount);
  78. playerScript1.confettiOnHit = control.confetti;
  79. playerScript2.confettiOnHit = control.confetti;
  80. playerScript3.confettiOnHit = control.confetti;
  81. playerScript4.confettiOnHit = control.confetti;
  82. }
  83. public void sccore (float scoreMax){
  84. control.maxScore = Mathf.RoundToInt(scoreMax);
  85. scoreText.GetComponent<Text> ().text = "" + Mathf.RoundToInt(scoreMax);
  86. playerScript1.maxScore = control.maxScore;
  87. playerScript2.maxScore = control.maxScore;
  88. playerScript3.maxScore = control.maxScore;
  89. playerScript4.maxScore = control.maxScore;
  90. }
  91. public void mute (bool muted){
  92. if (muted)
  93. AudioListener.volume = 0.0f;
  94. else
  95. AudioListener.volume = 1.0f;
  96. }
  97. public void dispID (bool visible){
  98. id1.idVanishDisp = visible;
  99. id2.idVanishDisp = visible;
  100. id3.idVanishDisp = visible;
  101. id4.idVanishDisp = visible;
  102. }
  103. public void exitLevel (){
  104. Time.timeScale = 1.0f;
  105. exit = true;
  106. }
  107. public void resumeGame(){
  108. paused = false;
  109. }
  110. }