// This function modirfies the Speed of the player and Background based on input. void ModirfyScrolling(float x) { if (x < 0) { if (paralax.getScrollspeed() < 0) { paralax.ModirfySpeed(-accelerationRate); } else { float LerpingValue = Mathf.Lerp(paralax.getScrollspeed(), -1f, 0.5f); paralax.SetScrollSpeed(LerpingValue); turn = true; } } if (x > 0) { if (paralax.getScrollspeed() > 0) { paralax.ModirfySpeed(accelerationRate); } else { float LerpingValue = Mathf.Lerp(paralax.getScrollspeed(), 1f, 0.5f); paralax.SetScrollSpeed(LerpingValue); turn = true; } } }
// Update is called once per frame void LateUpdate() { float step = speed * Time.deltaTime; CamY = Mathf.Clamp(player.position.y, cameraMinposY, cameraMaxposY); if (paralax.getScrollspeed() > 0) { CamX = 6; } else { CamX = -6; } offset = new Vector3(CamX, CamY, transform.position.z); transform.position = Vector3.MoveTowards(transform.position, offset, step); }