Advertisement
Guest User

Trainingsmanager

a guest
Jun 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.Timeline;
  7. using UnityEngine.Playables;
  8.  
  9. public class TrainingManager : MonoBehaviour {
  10.  
  11. public Camera mainCamera;
  12. public Text taskText;
  13. public Text errorText;
  14. public PlayableDirector timeline;
  15. int step;
  16. float diff;
  17.  
  18. double[] steps =
  19. {
  20. 0/60,
  21. 200/60,
  22. 787/60,
  23. 1094/60,
  24. 1620/60,
  25. 2370/60,
  26. /*0,
  27. 182 /60,
  28. 815/60,
  29. 1745/60,
  30. 2160/60,
  31. 2410/60*/
  32.  
  33. };
  34.  
  35. public GameObject[] objekte;
  36. private int currentStep =0;
  37. private int errorCounter =0;
  38. private LayerMask mask;
  39. [TextArea]
  40. public List<string> taskList = new List<string>();
  41.  
  42. // Use this for initialization
  43. void Start () {
  44.  
  45. mask = LayerMask.GetMask("Hitbox");
  46. timeline.Play();
  47. timeline.playableGraph.GetRootPlayable(0).SetSpeed(0);
  48. currentStep++;
  49. //taskText.text = taskList[currentStep - 1];
  50.  
  51.  
  52. }
  53.  
  54. // Update is called once per frame
  55. private void Update () {
  56. if (Input.GetKey("escape"))
  57. {
  58. Application.Quit();
  59. }
  60.  
  61. diff = (float)timeline.time - (float)steps[step];
  62.  
  63. if (Mathf.Abs(diff) > Time.deltaTime)
  64. timeline.time -= Mathf.Sign(diff) * Time.deltaTime;
  65. else
  66. timeline.playableGraph.GetRootPlayable(0).SetSpeed(0);
  67.  
  68.  
  69. if (Input.GetMouseButtonDown(0)&& currentStep < 2)
  70. {
  71. Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
  72. RaycastHit hit;
  73.  
  74. if (Physics.Raycast(ray, out hit, mask))
  75. {
  76. if (hit.collider.gameObject.Equals(objekte[3]))
  77. {
  78. Debug.Log(currentStep);
  79. SetNewStatus();
  80. }
  81. else
  82. {
  83. errorCounter++;
  84. errorText.text = "Mistakes: " + errorCounter.ToString();
  85. }
  86. }
  87. }
  88. else if (Input.GetMouseButtonDown(0) && currentStep == 2)
  89. {
  90. Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
  91. RaycastHit hit;
  92.  
  93. if (Physics.Raycast(ray, out hit, mask))
  94. {
  95. if (hit.collider.gameObject.Equals(objekte[0]))
  96. {
  97. Debug.Log(currentStep);
  98. SetNewStatus();
  99.  
  100. }
  101. else
  102. {
  103. errorCounter++;
  104. errorText.text = "Mistakes: " + errorCounter.ToString();
  105. }
  106. }
  107.  
  108. }
  109.  
  110. else if (Input.GetMouseButtonDown(0) && currentStep == 3)
  111. {
  112. Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
  113. RaycastHit hit;
  114.  
  115. if (Physics.Raycast(ray, out hit, mask))
  116. {
  117. if (hit.collider.gameObject.Equals(objekte[3]))
  118. {
  119. Debug.Log(currentStep);
  120. SetNewStatus();
  121. }
  122. else
  123. {
  124. errorCounter++;
  125. errorText.text = "Mistakes: " + errorCounter.ToString();
  126. }
  127. }
  128.  
  129. }
  130.  
  131. else if (Input.GetMouseButtonDown(0) && currentStep == 4)
  132. {
  133. Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
  134. RaycastHit hit;
  135.  
  136. if (Physics.Raycast(ray, out hit, mask))
  137. {
  138. if (hit.collider.gameObject.Equals(objekte[3]))
  139. {
  140. Debug.Log(currentStep);
  141. SetNewStatus();
  142.  
  143. }
  144. else
  145. {
  146. errorCounter++;
  147. errorText.text = "Mistakes: " + errorCounter.ToString();
  148. }
  149. }
  150.  
  151. }
  152.  
  153. else if (Input.GetMouseButtonDown(0) && currentStep == 5)
  154. {
  155. Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
  156. RaycastHit hit;
  157.  
  158. if (Physics.Raycast(ray, out hit, mask))
  159. {
  160. if (hit.collider.gameObject.Equals(objekte[1]))
  161. {
  162. Debug.Log(currentStep);
  163. SetNewStatus();
  164. errorText.text = "Gratulation, Sie hatten insgesamt " + errorCounter.ToString() + " Fehler";
  165. }
  166. else
  167. {
  168. errorCounter++;
  169. errorText.text = "Mistakes: " + errorCounter.ToString();
  170. }
  171. }
  172.  
  173. }
  174.  
  175.  
  176.  
  177. /*
  178. if (Input.GetMouseButtonDown(0))
  179. {
  180. Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
  181. RaycastHit hit;
  182.  
  183. if (Physics.Raycast(ray, out hit, 100f, mask))
  184. {
  185. if (currentStep == int.Parse(hit.transformation.tag))
  186. {
  187. Debug.Log(currentStep);
  188. animation.stepForward();
  189. SetNewStatus();
  190. }
  191. else
  192. {
  193. errorCounter++;
  194. errorText.text = "Fehler: " + errorCounter.ToString();
  195. }
  196. }
  197. }*/
  198.  
  199. }
  200.  
  201. void SetNewStatus()
  202. {
  203.  
  204. currentStep++;
  205.  
  206. if(step < steps.Length - 1) step++;
  207. diff = (float)timeline.time - (float)steps[step];
  208.  
  209. if (Mathf.Abs(diff) > Time.deltaTime)
  210. timeline.time -= Mathf.Sign(diff) * Time.deltaTime;
  211. else
  212. timeline.playableGraph.GetRootPlayable(0).SetSpeed(0);
  213. }
  214.  
  215. public void Help()
  216. {
  217. taskText.text = taskList[currentStep - 1];
  218. }
  219.  
  220.  
  221.  
  222.  
  223.  
  224. public void ReloadScene() {
  225. SceneManager.LoadScene(SceneManager.GetActiveScene().name);
  226. }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement