|
@@ -1,4 +1,5 @@
|
|
|
-using Controller.Bicycle;
|
|
|
+using System.Linq;
|
|
|
+using Controller.Bicycle;
|
|
|
using UnityEngine;
|
|
|
|
|
|
namespace Routes
|
|
@@ -24,15 +25,48 @@ namespace Routes
|
|
|
routes[selectedRoute].OnStartEntered += OnOnStartEntered;
|
|
|
routes[selectedRoute].OnFinishPassed += OnOnFinishPassed;
|
|
|
|
|
|
+ PlaceBike();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PlaceBike()
|
|
|
+ {
|
|
|
+ var firstTurnPos = routes[selectedRoute].items.First().turn.transform.position;
|
|
|
|
|
|
var startTransform = routes[selectedRoute].start.gameObject.transform;
|
|
|
var startRotationEuler = startTransform.rotation.eulerAngles;
|
|
|
+
|
|
|
+ var difStartFirstTurn = firstTurnPos - startTransform.position;
|
|
|
+ Vector3 bikeDirection = Vector3.zero;
|
|
|
+ Vector3 bikeRotation = Vector3.zero;
|
|
|
+
|
|
|
+ if (difStartFirstTurn.x > 1)
|
|
|
+ {
|
|
|
+ bikeDirection = startTransform.right;
|
|
|
+ bikeRotation = new Vector3(0, -90, 0);
|
|
|
+ }
|
|
|
+ else if (difStartFirstTurn.z > 1)
|
|
|
+ {
|
|
|
+ bikeDirection = startTransform.forward;
|
|
|
+ bikeRotation = new Vector3(0, -180, 0);
|
|
|
+ }
|
|
|
+ else if (difStartFirstTurn.x < -1)
|
|
|
+ {
|
|
|
+ bikeDirection = -startTransform.right;
|
|
|
+ bikeRotation = new Vector3(0, 90, 0);
|
|
|
+ }
|
|
|
+ else if (difStartFirstTurn.z < -1)
|
|
|
+ {
|
|
|
+ bikeDirection = -startTransform.forward;
|
|
|
+ bikeRotation = new Vector3(0, 180, 0);
|
|
|
+ }
|
|
|
+
|
|
|
bicycleGameObject = bicycle.gameObject;
|
|
|
bicycleGameObject.transform.SetPositionAndRotation(
|
|
|
- startTransform.position + startTransform.right * 12,
|
|
|
- Quaternion.Euler(startRotationEuler + new Vector3(0, -90, 0)));
|
|
|
+ startTransform.position + bikeDirection * 12,
|
|
|
+ Quaternion.Euler(startRotationEuler + bikeRotation));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void OnOnFinishPassed()
|
|
|
{
|
|
|
//bicycle.enabled = false;
|