SlalomPassed.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Study;
  2. using SchoenLogger.HOHCI;
  3. using UnityEngine;
  4. public enum WaypointType { slalom1, slalom2, finish};
  5. namespace SchoenLogger.HOHCI
  6. {
  7. public class SlalomPassed : MonoBehaviour
  8. {
  9. public WaypointType type;
  10. public Logger<HOHCIEntry, HOHCICondition> Logger;
  11. public GameObject bikePlayer;
  12. // Only relevant to check finish
  13. public int routeId;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. bikePlayer = GameObject.Find("bike");
  18. }
  19. // Update is called once per frame
  20. void Update()
  21. {
  22. }
  23. private void OnTriggerEnter(Collider other)
  24. {
  25. if (other.CompareTag("bike"))
  26. {
  27. // Set finished in statistics, so success is logged
  28. var bikePlayer = GameObject.Find("bike");
  29. var playerStats = bikePlayer.GetComponent<PlayerStats>();
  30. Debug.Log("Waypoint passed");
  31. if (type == WaypointType.finish)
  32. {
  33. var cm = GameObject.Find("ExperimentManager").GetComponent<ConditionManager>();
  34. int routeNbr = cm.GetRouteNumber();
  35. // If type is finish, we need to make sure we only set for right finish
  36. // because routes are overlapping
  37. if (routeId == routeNbr)
  38. {
  39. playerStats.SetWaypointPassed(type);
  40. }
  41. }
  42. else
  43. {
  44. playerStats.SetWaypointPassed(type);
  45. }
  46. WriteToLog();
  47. }
  48. }
  49. private void WriteToLog()
  50. {
  51. if (Logger == null) return;
  52. var playerStats = bikePlayer.GetComponent<PlayerStats>();
  53. HOHCIEntry entry = new HOHCIEntry();
  54. entry.Time = Time.time;
  55. entry.ParticipantID = playerStats.participantId; //TODO
  56. entry.ReachedFinish = playerStats.hasFinished;
  57. entry.ReachedSlalom1 = playerStats.hasFinishedSlalom1;
  58. entry.ReachedSlalom2 = playerStats.hasFinishedSlalom2;
  59. entry.CoinCount = playerStats.coinCounter;
  60. entry.CollisionCount = playerStats.collisionCounter;
  61. Logger.Log(entry);
  62. }
  63. }
  64. }