SlalomPassed.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. if (routeId == routeNbr)
  32. {
  33. playerStats.SetWaypointPassed(type);
  34. }
  35. }
  36. else
  37. {
  38. playerStats.SetWaypointPassed(type);
  39. }
  40. }
  41. }
  42. }