using System.Linq; using Controller.Bicycle; using UnityEngine; namespace Routes { public class RouteManager : MonoBehaviour { public Route[] routes; public int selectedRoute; public int visibleLength = 3; public RbBicycleController bicycle; public Logging.Base.Logging logging; public GameObject showOnFinish; private GameObject bicycleGameObject; private void Start() { for (var i = 0; i < routes.Length; i++) { routes[i].gameObject.SetActive(i == selectedRoute); } 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 || difStartFirstTurn.z > 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 || difStartFirstTurn.z < -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 + bikeDirection * 12, Quaternion.Euler(startRotationEuler + bikeRotation)); } private void OnOnFinishPassed() { //bicycle.enabled = false; Instantiate(showOnFinish, bicycle.transform); Destroy(logging.gameObject); } private void OnOnStartEntered() { logging.gameObject.SetActive(true); } } }