public void OnSwipeDetected(GameResources.Direction direction) { if (SwipeDetected != null) { SwipeDetected(direction); } }
public void OnSwipeDetected(GameResources.Direction direction) { if (direction == GameResources.Direction.RIGHT) { ChangeCar("Previous"); } else if (direction == GameResources.Direction.LEFT) { ChangeCar("Next"); } }
public void OnSwipeDetected(GameResources.Direction direction) { if (!car) { return; } if (direction == GameResources.Direction.UP) { StartCoroutine(Jump()); } else { ChangeLane(direction); } }
private void ChangeLane(GameResources.Direction direction) { if (PlayerChangedLane != null) { PlayerChangedLane(this); } if (nextLane != Lane.NONE) { currentLane = nextLane; } //change lanes independent of frame rate //changing lane will take exactly as much as lanechangetime //variable , regardless of how many frames per second //****Inaccurate calculations: i shouldn't use fixed delta time //in this coroutine since fixed delta time here will be //different than next frame's. changingLanes = true; //the name of the parameter to trigger animation clip string animKey = ""; switch (direction) { case GameResources.Direction.RIGHT: { animKey = "RightLaneChange"; laneChangeDirection = GameResources.Direction.RIGHT; if (currentLane == Lane.RIGHT) { return; } else if (currentLane == Lane.MIDDLE) { nextLane = Lane.RIGHT; } else //if current lane is left { nextLane = Lane.MIDDLE; } break; } case GameResources.Direction.LEFT: { animKey = "LeftLaneChange"; laneChangeDirection = GameResources.Direction.LEFT; if (currentLane == Lane.LEFT) { return; } else if (currentLane == Lane.MIDDLE) { nextLane = Lane.LEFT; } else //if current lane is left { nextLane = Lane.MIDDLE; } break; } } //assign lane change target based on where the lane changing direction will be switch (nextLane) { case Lane.RIGHT: { laneChangeTarget = rightLane.transform.position; break; } case Lane.LEFT: { laneChangeTarget = leftLane.transform.position; break; } case Lane.MIDDLE: { laneChangeTarget = middleLane.transform.position; break; } } cachedXPos = car.transform.position.x; horizontalMoveAmount = (cachedXPos - laneChangeTarget.x); laneChangeStep = (horizontalMoveAmount / 15f); anim.SetTrigger(animKey); }