2
0

StraightRoadExtras.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using Pools;
  3. using Routes;
  4. using UnityEngine;
  5. namespace Roads
  6. {
  7. [RequireComponent(typeof(BoxCollider))]
  8. public class StraightRoadExtras : MonoBehaviour, IRoad
  9. {
  10. public GameObject arcPrefab;
  11. private GameObject arc;
  12. private bool hasArc;
  13. public TriggerState ArcState { get; private set; } = TriggerState.Outside;
  14. public float SlopeDeg { get; private set; }
  15. public float MinY { get; private set; }
  16. private void Start()
  17. {
  18. SlopeDeg = transform.localRotation.eulerAngles.z;
  19. MinY = GetComponent<BoxCollider>().bounds.center.y;
  20. }
  21. public void ShowArc()
  22. {
  23. arc = Instantiate(arcPrefab, transform);
  24. hasArc = arc != null;
  25. }
  26. private void OnTriggerEnter(Collider other)
  27. {
  28. if (hasArc && other.CompareTag("bike"))
  29. {
  30. ArcState = TriggerState.Inside;
  31. }
  32. }
  33. private void OnTriggerExit(Collider other)
  34. {
  35. if (hasArc && other.CompareTag("bike"))
  36. {
  37. Destroy(arc);
  38. ArcState = TriggerState.Outside;
  39. }
  40. }
  41. }
  42. }