Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.UI;
  5.  
  6. /// <summary>
  7. /// Controlling the scene transitions as the detective moves around the Ron Cooke Hub
  8. /// </summary>
  9. public class SceneTransitions : MonoBehaviour {
  10. /// <summary>
  11. /// Will hold the transform position of Detective if the character tries to walk out of bounds
  12. /// </summary>
  13. private Vector3 pos;
  14. /// <summary>
  15. /// Fades to black and then loads a scene.
  16. /// </summary>
  17. /// <returns>Yield WaitForSeconds</returns>
  18. /// <param name="scene">Scene index to load</param>
  19. IEnumerator fadeLoadScene(int scene){
  20. GameObject overlayPanel = GameObject.Find ("OverlayPanel");
  21. overlayPanel.SetActive (true);
  22. overlayPanel.GetComponent<Image> ().CrossFadeAlpha (1f, 1f, false);
  23. yield return new WaitForSeconds (1);
  24. SceneManager.LoadScene (scene);
  25. }
  26.  
  27. private void stopDetective(bool directionIsRight, Collider detective){
  28. if (directionIsRight) {
  29. detective.GetComponent<Detective> ().canWalkRight = false;
  30. pos = detective.transform.position;
  31. pos.x = 6.8f;
  32. detective.transform.position = pos;
  33. } else {
  34. detective.GetComponent<Detective> ().canWalkLeft = false;
  35. pos = detective.transform.position;
  36. pos.x = -7.5f;
  37. detective.transform.position = pos;
  38. }
  39. }
  40.  
  41. /// <summary>
  42. /// Raises the mouse down event for use when DoorQuads are clicked.
  43. /// </summary>
  44. public void OnMouseDown(){
  45. if (gameObject.name == "LobbyDoorQuad") {
  46. GameObject.Find ("Detective").GetComponent<Detective> ().walkInDirection = 2;
  47. StartCoroutine (fadeLoadScene (3));
  48. } else if (gameObject.name == "KitchenDoorQuad") {
  49. GameObject.Find ("Detective").GetComponent<Detective> ().walkInDirection = 2;
  50. StartCoroutine (fadeLoadScene (7));
  51. } else if (gameObject.name == "StudioDoorQuad") {
  52. GameObject.Find ("Detective").GetComponent<Detective> ().walkInDirection = 2;
  53. StartCoroutine (fadeLoadScene (9));
  54. } else if (gameObject.name == "StudioExitDoorQuad") {
  55. GameObject.Find ("Detective").GetComponent<Detective> ().walkInDirection = 0;
  56. StartCoroutine (fadeLoadScene (8));
  57. }
  58. }
  59. /// <summary>
  60. /// Handles what happens when player walks into a transparent collider at the edge of either side of the scene.
  61. /// </summary>
  62. /// <param name="detective">Passed by the colliderm; the GameObject that has caused the collision.</param>
  63. void OnTriggerEnter(Collider detective){
  64. if (Time.timeSinceLevelLoad > 0.2){ //enough time for them to walk on screen
  65. switch (this.gameObject.name) {
  66. case "Room1L":
  67. stopDetective(false,detective);
  68. break;
  69.  
  70. case "Room1R":
  71. if (GameObject.Find ("SceneController").GetComponent<Room1Controller> ().canProgress ()){
  72. detective.GetComponent<Detective> ().walkInDirection = 1;
  73. StartCoroutine (fadeLoadScene (4));
  74. } else {
  75. stopDetective(true,detective);
  76. }
  77. break;
  78.  
  79. case "Room2L": //room2 is lobby
  80. detective.GetComponent<Detective>().walkInDirection = 2;
  81. StartCoroutine(fadeLoadScene(6)); // load cafe
  82. break;
  83.  
  84. case "Room2R":
  85. detective.GetComponent<Detective>().walkInDirection = 0;
  86. StartCoroutine(fadeLoadScene(5)); // load train station
  87. break;
  88.  
  89. case "Room3L": //room3 is train station
  90. detective.GetComponent<Detective>().walkInDirection = 2;
  91. StartCoroutine(fadeLoadScene(4)); // load lobby
  92. break;
  93.  
  94. case "Room3R":
  95. detective.GetComponent<Detective>().walkInDirection = 0;
  96. StartCoroutine(fadeLoadScene(10)); // load toilets
  97. break;
  98.  
  99. case "Room4L": //room4 is cafe
  100. detective.GetComponent<Detective>().walkInDirection = 2;
  101. StartCoroutine(fadeLoadScene(8)); // load bar
  102. break;
  103.  
  104. case "Room4R":
  105. detective.GetComponent<Detective>().walkInDirection = 0;
  106. StartCoroutine(fadeLoadScene(4)); // load lobby
  107. break;
  108.  
  109. case "Room5L": //room 5 is kitchen
  110. stopDetective(false,detective);
  111. break;
  112.  
  113. case "Room5R":
  114. detective.GetComponent<Detective>().walkInDirection = 0;
  115. StartCoroutine(fadeLoadScene(6)); // load cafe
  116. break;
  117.  
  118. case "Room6L": //room 6 is bar
  119. detective.GetComponent<Detective>().walkInDirection = 2;
  120. StartCoroutine(fadeLoadScene(10)); // load toilets
  121. break;
  122.  
  123. case "Room6R":
  124. detective.GetComponent<Detective>().walkInDirection = 0;
  125. StartCoroutine(fadeLoadScene(6)); // load cafe
  126. break;
  127.  
  128. case "Room7L": //room 7 is studio
  129. stopDetective(false, detective);
  130. break;
  131.  
  132. case "Room7R":
  133. stopDetective (true, detective);
  134. break;
  135.  
  136. case "Room8L": //room 8 is toilets
  137. detective.GetComponent<Detective>().walkInDirection = 2;
  138. StartCoroutine(fadeLoadScene(5)); // load station
  139. break;
  140.  
  141. case "Room8R":
  142. detective.GetComponent<Detective>().walkInDirection = 0;
  143. StartCoroutine(fadeLoadScene(8)); // load bar
  144. break;
  145.  
  146. default:
  147. break;
  148. }
  149.  
  150.  
  151. }
  152. }
  153.  
  154. public void fadeAndLoadScene(int roomBuildindex){
  155. StartCoroutine(fadeLoadScene(roomBuildindex));
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement