// Start is called before the first frame update void Start() { TileRail rail = GetComponent <TileRail>(); rail.onTypeChanged.AddListener(OnTileTypeChanged); InstantiateModel(rail.type); RotateRailModel(rail.type); }
void FollowRails(float progressDelay) { if (followTarget.RealProgress > 1) { //If the progress is above one, it means the target as yet to change tile but is effectyvely on the next tile, so go one time less far. progressDelay--; } float progressAmount = followTarget.RealProgress % 1 - progressDelay; //Finds the tile we are in while (progressAmount < 0) { //Find the next tile currentCoords = TileMap.Instance.GetNextTileCoords(currentCoords, ref entryDirection); //Remove one from progress since we moved one tile progressAmount++; } //Place ourself into this tile TileRail tile = TileMap.Instance.GetTile(currentCoords); if (tile != lastTile) { tile.somethingOnRailState.Add(isOnRailToken); if (lastTile != null) { lastTile.somethingOnRailState.Remove(isOnRailToken); } lastTile = tile; onNewCoords.Invoke(currentCoords); } //We are going the opposite way that we are doing the search, so invert it goingReverse = !tile.IsGoingReverse(entryDirection); progress = progressAmount; }
// Update is called once per frame void LateUpdate() { if (GameManager.gameIsOver) { return; } TileRail tile = TileMap.Instance.GetTile(railWalker.currentCoords); Vector3 targetPosition = tile.GetPoint(railWalker.EffectiveProgress); targetPosition.y = transform.position.y; transform.position = targetPosition; Vector3 lookAtPosition; if (railWalker.goingReverse) { lookAtPosition = targetPosition - tile.GetDirection(railWalker.EffectiveProgress); } else { lookAtPosition = targetPosition + tile.GetDirection(railWalker.EffectiveProgress); } lookAtPosition.y = transform.position.y;; transform.LookAt(lookAtPosition); }
private void OnSceneGUI() { rail = target as TileRail; Draw(); }