Follow camera

Hello! help me please. I want make that camera follow for person if he became jump faster. I took idea from Crossy Road. Camera is move down with same speed. But when player became jump faster camera coordinate it and player “stay on middle of screen” bcs camera faster generate new levels. I want the player was unable to get closer to the screen verhts. when he reached the center of the camera starts to move faster down. how to implement it?

Try something like this (put it on the camera and make sure to set player to point at your player object):

using UnityEngine;

public class MoveCamera: MonoBehaviour
{
    public Transform player;

    // The Camera will always move at least at this speed
    public float minSpeed = 0.1f;
    // The speed up to be used if the player is all the way at the top of the screen
    public float maxSpeedUp = 1f;

    // The distance between the center of the screen and the top of the screen
    private float distanceCenterToTop;

    void Start()
    {
        // Assumes that the camera starts at the center of the screen in the beginning
        distanceCenterToTop = GetComponent<Camera>().ViewportToWorldPoint(Vector3.one).y - transform.position.y;
    }

    private void LateUpdate()
    {
        float speed = minSpeed;

        // If the player is above the middle of the screen
        if (transform.position.y < player.transform.position.y)
        {
            // Calculate a linear speed up that increases the further up the screen the player is
            speed += Mathf.Lerp(
                0,
                maxSpeedUp,
                // How far from the center has the player moved, normalized
                (player.transform.position.y - transform.position.y)/distanceCenterToTop);
        }

        // Move the camera
        transform.Translate(Vector3.up * speed * Time.deltaTime);
    }
}

Thk you very much) Its work))))

Can I ask you one question yet/ i dont want creae a new theme. I have a moveig platform. Its should move from left to right and back when it toach the edge of left or right screen. I create a new object and try to check attach to them but its doesnt work( How can fix this code to work?

    void Update ()
    {
    transform.Translate (Vector3.left*Time.deltaTime*speed);
        }
    void OnCollision2D (Collision2D col)
    {
        if (col.gameObject.name == "box_left") {
            speed = -speed;

        }    }}

Now I checked this script more carefly. and one problem. I have a script to move and create a new stick (like a ground) player jump up on it. your script work with it. and one player jump more higher this stick move faster. But! They have coordinate. They appear in place with y = 5. and when i move faster camera this y fall down. and sticks became appear in coordinator =3. or coordinator =0 and etc. I dont understand why it happening. this coordinatore can move? i thought its every time in one place. How I cant stop moving coordinator that my stick every time appear in the top in cooridate y=5.?

Hmm, I’m not sure I understand the problem fully, but… Since you are moving the camera you will need to place new platforms at new positions. As the camera moves upwards, you will need to place the new platforms higher and higher in order for them to appear on-screen.

If that isn’t the problem, perhaps you have a screenshot or video that shows off the problem?

I solved problem with camera. But I hve yet a problem with moing [latform. Yes I have a component rigidbody 2d and I switch “is kinestatic” becase its fall down . but it doesnt work i cant underatsnd why(((

I solved this problem) Theme closed)