Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using UnityEngine.Timeline;
- using UnityEngine.Playables;
- public class TrainingManager : MonoBehaviour {
- public Camera mainCamera;
- public Text taskText;
- public Text errorText;
- public PlayableDirector timeline;
- int step;
- float diff;
- double[] steps =
- {
- 0/60,
- 200/60,
- 787/60,
- 1094/60,
- 1620/60,
- 2370/60,
- /*0,
- 182 /60,
- 815/60,
- 1745/60,
- 2160/60,
- 2410/60*/
- };
- public GameObject[] objekte;
- private int currentStep =0;
- private int errorCounter =0;
- private LayerMask mask;
- [TextArea]
- public List<string> taskList = new List<string>();
- // Use this for initialization
- void Start () {
- mask = LayerMask.GetMask("Hitbox");
- timeline.Play();
- timeline.playableGraph.GetRootPlayable(0).SetSpeed(0);
- currentStep++;
- //taskText.text = taskList[currentStep - 1];
- }
- // Update is called once per frame
- private void Update () {
- if (Input.GetKey("escape"))
- {
- Application.Quit();
- }
- diff = (float)timeline.time - (float)steps[step];
- if (Mathf.Abs(diff) > Time.deltaTime)
- timeline.time -= Mathf.Sign(diff) * Time.deltaTime;
- else
- timeline.playableGraph.GetRootPlayable(0).SetSpeed(0);
- if (Input.GetMouseButtonDown(0)&& currentStep < 2)
- {
- Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, mask))
- {
- if (hit.collider.gameObject.Equals(objekte[3]))
- {
- Debug.Log(currentStep);
- SetNewStatus();
- }
- else
- {
- errorCounter++;
- errorText.text = "Mistakes: " + errorCounter.ToString();
- }
- }
- }
- else if (Input.GetMouseButtonDown(0) && currentStep == 2)
- {
- Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, mask))
- {
- if (hit.collider.gameObject.Equals(objekte[0]))
- {
- Debug.Log(currentStep);
- SetNewStatus();
- }
- else
- {
- errorCounter++;
- errorText.text = "Mistakes: " + errorCounter.ToString();
- }
- }
- }
- else if (Input.GetMouseButtonDown(0) && currentStep == 3)
- {
- Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, mask))
- {
- if (hit.collider.gameObject.Equals(objekte[3]))
- {
- Debug.Log(currentStep);
- SetNewStatus();
- }
- else
- {
- errorCounter++;
- errorText.text = "Mistakes: " + errorCounter.ToString();
- }
- }
- }
- else if (Input.GetMouseButtonDown(0) && currentStep == 4)
- {
- Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, mask))
- {
- if (hit.collider.gameObject.Equals(objekte[3]))
- {
- Debug.Log(currentStep);
- SetNewStatus();
- }
- else
- {
- errorCounter++;
- errorText.text = "Mistakes: " + errorCounter.ToString();
- }
- }
- }
- else if (Input.GetMouseButtonDown(0) && currentStep == 5)
- {
- Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, mask))
- {
- if (hit.collider.gameObject.Equals(objekte[1]))
- {
- Debug.Log(currentStep);
- SetNewStatus();
- errorText.text = "Gratulation, Sie hatten insgesamt " + errorCounter.ToString() + " Fehler";
- }
- else
- {
- errorCounter++;
- errorText.text = "Mistakes: " + errorCounter.ToString();
- }
- }
- }
- /*
- if (Input.GetMouseButtonDown(0))
- {
- Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, 100f, mask))
- {
- if (currentStep == int.Parse(hit.transformation.tag))
- {
- Debug.Log(currentStep);
- animation.stepForward();
- SetNewStatus();
- }
- else
- {
- errorCounter++;
- errorText.text = "Fehler: " + errorCounter.ToString();
- }
- }
- }*/
- }
- void SetNewStatus()
- {
- currentStep++;
- if(step < steps.Length - 1) step++;
- diff = (float)timeline.time - (float)steps[step];
- if (Mathf.Abs(diff) > Time.deltaTime)
- timeline.time -= Mathf.Sign(diff) * Time.deltaTime;
- else
- timeline.playableGraph.GetRootPlayable(0).SetSpeed(0);
- }
- public void Help()
- {
- taskText.text = taskList[currentStep - 1];
- }
- public void ReloadScene() {
- SceneManager.LoadScene(SceneManager.GetActiveScene().name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement