Tanoda
FoodPrintManager.cs
Go to the documentation of this file.
1using NaughtyAttributes;
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
6
7public class FoodPrintManager : MonoBehaviour
8{
10 internal float time = 0.0f;
11 private bool change = false;
12 public float freq;
13 private GameObject activeGo;
14 // Start is called before the first frame update
15 void Start()
16 {
17
18 }
19
20 void Update()
21 {
22 if (!ConveyorBeltManager.instance.started) return;
23
24 time += Time.deltaTime;
25 var footPrint = RightFoot.transform.parent;
26 footPrint.transform.position = new Vector3(VRCamera.transform.position.x, footPrint.transform.position.y, VRCamera.transform.position.z);
27 footPrint.transform.forward = VRCamera.transform.forward;
28 footPrint.transform.eulerAngles = new Vector3(0, footPrint.transform.eulerAngles.y, 0);
29
30 if (time >= freq)
31 {
32 time = 0;
33 if (!change)
34 {
35 SaveSteps(RightFoot);
36 change = true;
37 }
38 else
39 {
40 SaveSteps(LeftFoot);
41 change = false;
42 }
43
44 }
45 }
46 [Button]
47 public void showSteps()
48 {
49 StartCoroutine(ShowHistory());
50 }
51 public IEnumerator ShowHistory()
52 {
53 var footPrints = History.GetComponentsInChildren<SpriteRenderer>(true);
54 foreach (var foot in footPrints)
55 {
56 ShowFootPrint(foot.gameObject);
57 yield return new WaitForSeconds(0.5f);
58
59 }
60 ResultCanvas.SetActive(true);
61 ReplayCanvas.SetActive(true);
62 }
63
64 private void SaveSteps(GameObject foot)
65 {
66 var rf = Instantiate(foot, History.transform);
67 rf.transform.position = foot.transform.position;
68 rf.transform.eulerAngles = foot.transform.eulerAngles;
69 }
70 private void ShowFootPrint(GameObject fp)
71 {
72
73 fp.SetActive(true);
74 activeGo = fp;
75 activeGo.GetComponent<EventManager>().DelayedHide.AddListener(hideFoot);
76 activeGo.GetComponent<EventManager>().DelayedHide?.Invoke();
77
78 }
79 private void hideFoot()
80 {
81 StartCoroutine(DelayedHideEvent(activeGo));
82 }
83 private IEnumerator DelayedHideEvent(GameObject fp)
84 {
85 float duration = 0;
86 var alpha = fp.GetComponentInChildren<SpriteRenderer>(true).color;
87 while (duration < 3)
88 {
89 duration += Time.deltaTime;
90 alpha.a = Mathf.Lerp(1, 0, duration / 3);
91 fp.GetComponentInChildren<SpriteRenderer>(true).color = alpha;
92 yield return null;
93 }
94
95 fp.SetActive(false);
96
97
98 }
99}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
GameObject ResultCanvas
GameObject LeftFoot
GameObject History
GameObject VRCamera
IEnumerator ShowHistory()
GameObject RightFoot
GameObject ReplayCanvas