using Study; using SchoenLogger.HOHCI; using UnityEngine; public enum WaypointType { slalom1, slalom2, finish}; namespace SchoenLogger.HOHCI { public class SlalomPassed : MonoBehaviour { public WaypointType type; public Logger Logger; public GameObject bikePlayer; // Only relevant to check finish public int routeId; // Start is called before the first frame update void Start() { bikePlayer = GameObject.Find("bike"); } // Update is called once per frame void Update() { } private void OnTriggerEnter(Collider other) { if (other.CompareTag("bike")) { // Set finished in statistics, so success is logged var bikePlayer = GameObject.Find("bike"); var playerStats = bikePlayer.GetComponent(); Debug.Log("Waypoint passed"); if (type == WaypointType.finish) { var cm = GameObject.Find("ExperimentManager").GetComponent(); int routeNbr = cm.GetRouteNumber(); // If type is finish, we need to make sure we only set for right finish // because routes are overlapping if (routeId == routeNbr) { playerStats.SetWaypointPassed(type); } } else { playerStats.SetWaypointPassed(type); } // we want to write a log entry each time a waypoint is passed WriteToLog(); } } private void WriteToLog() { if (Logger == null) return; var playerStats = bikePlayer.GetComponent(); HOHCIEntry entry = new HOHCIEntry(); entry.Time = Time.time; entry.ParticipantID = playerStats.participantId; entry.steeringCondition = playerStats.condition; entry.ReachedFinish = playerStats.hasFinished; entry.ReachedSlalom1 = playerStats.hasFinishedSlalom1; entry.ReachedSlalom2 = playerStats.hasFinishedSlalom2; entry.CoinCount = playerStats.coinCounter; entry.CollisionCount = playerStats.collisionCounter; Logger.Log(entry); } } }