private void ComputeAutoDirection(ParallaxEffectElement element) { if (!autoDirection) { return; } element.direction = baseDirection; }
private void MoveElement(ParallaxEffectElement element) { var vector = Util.DirectionToVector(element.direction); element.gameObject.transform.Translate(vector * element.speed * Time.deltaTime); if (ReachEndPosition(element)) { element.gameObject.transform.position = startPosition.position; } }
private void ComputeAutoSpeed(ParallaxEffectElement element) { if (!autoSpeed) { return; } element.speed = elementSpeed; if (Mathf.Sign(elementSpeed) > 0) { elementSpeed *= baseSpeedDiviser; } else { elementSpeed = 0; } }
private bool ReachEndPosition(ParallaxEffectElement element) { switch (element.direction) { case Direction.LEFT: return(element.gameObject.transform.position.x < endPosition.position.x); case Direction.RIGHT: return(element.gameObject.transform.position.x > endPosition.position.x); case Direction.TOP: return(element.gameObject.transform.position.y > endPosition.position.y); case Direction.BOTTOM: return(element.gameObject.transform.position.y < endPosition.position.y); default: break; } return(false); }