SlalomPassed.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Study;
  2. using UnityEngine;
  3. public enum WaypointType { slalom1, slalom2, finish};
  4. public class SlalomPassed : MonoBehaviour
  5. {
  6. public WaypointType type;
  7. // Only relevant to check finish
  8. public int routeId;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. }
  13. // Update is called once per frame
  14. void Update()
  15. {
  16. }
  17. private void OnTriggerEnter(Collider other)
  18. {
  19. if (other.CompareTag("bike"))
  20. {
  21. // Set finished in statistics, so success is logged
  22. var bikePlayer = GameObject.Find("bike");
  23. var playerStats = bikePlayer.GetComponent<PlayerStats>();
  24. Debug.Log("Waypoint passed");
  25. if (type == WaypointType.finish)
  26. {
  27. var cm = GameObject.Find("ExperimentManager").GetComponent<ConditionManager>();
  28. int routeNbr = cm.GetRouteNumber();
  29. // If type is finish, we need to make sure we only set for right finish
  30. // because routes are overlapping
  31. Debug.Log("Finish Number: " + routeNbr + ", Route ID:" + routeId);
  32. if (routeId == routeNbr)
  33. {
  34. playerStats.SetWaypointPassed(type);
  35. }
  36. }
  37. else
  38. {
  39. playerStats.SetWaypointPassed(type);
  40. }
  41. }
  42. }
  43. }