/// <summary> /// Convierte una ubicacion a string /// </summary> /// <param name="location"Ubicacion a transformar</param> /// <returns>String representando la ubicacion</returns> public static string ToString(Location location) { return "(" + location.Rail + ", " + location.X + ") - L:" + location.CanMoveLeft + " R:" + location.CanMoveRight; }
/// <summary> /// Convierte una coordenada de la via a una /// posicion real /// </summary> /// <param name="location">Coordenada</param> /// <returns>Posicion real</returns> public static Vector3 LocationToWorld(Location location) { Vector3 position = TrackOrigin; // Calculo la posicion en x position.x += (location.Rail + location.X) * RailSize; // Calculo la posicion en z position.z += location.TrackPercentage * (TrackEnd.z - TrackOrigin.z); return position; }
/// <summary> /// Cambia una ubicacion de carril /// </summary> /// <param name="location">Ubicacion a cambiar</param> /// <param name="direction">Direccion de cambio</param> public static Location ChangeRail(Location location, Direction direction) { location.Rail += direction == Direction.Left ? -1 : 1; location.X = 0.5f; location.CanMoveLeft = 0 <= location.Rail - 1; location.CanMoveRight = location.Rail + 1 < NumRails; return location; }
/// <summary> /// Actualiza la ToLocation para /// definir un carril objetivo /// </summary> /// <param name="direction">Direccion de cambio</param> public void ChangeRail(Direction direction) { if (!CanChangeRail(direction)) return; TargetLocation = Track.ChangeRail(CurrentLocation, direction); }
/// <summary> /// Inicializacion /// </summary> private void Awake() { Me = transform; TargetLocation = Track.WorldToLocation(Me.position); CurrentLocation = Track.WorldToLocation(Me.position); }
/// <summary> /// Actualizacion de calculos /// </summary> private void Update() { actualLocation = Track.WorldToLocation(Target.position); actualPosition = Track.LocationToWorld(actualLocation); }