2d camera along fixed path

I’m working on a 2d platformer. I want to implement a camera that moves along a fixed path based on player’s movement. Does the array works? or anyone has a better solution to achieve this? I’m really stuck at this camera. I’m running out of ideas. Any ideas?

I’ve considered doing something similar myself. Here’s a quick idea for it using triggers, but I can’t promise this is optimal. It’s just the simplest way I could think of.

First, I created a few triggers around the scene where your player will move through. I just used empty gameobjects with box colliders attached. (make sure to set “Is Trigger” in the inspector)

Then, I created some empty gameobjects at the positions you want the camera to move to.

On the triggers I added this small script:

using UnityEngine;
using System.Collections;

public class CameraTrigger : MonoBehaviour {
public GameObject camera;
public Transform cameraTarget;

    void OnTriggerEnter(Collider other) {
        camera.GetComponent<CameraFollow>().target = cameraTarget;

In the inspector for each one of your triggers, put your main camera in as the “camera” variable, and put one of the camera position objects you made as the “cameraTarget”.

Finally, attach this script to your main camera:

        using UnityEngine;
        using System.Collections;
        public class CameraFollow : MonoBehaviour {
        	public float cameraSpeed = 2 ; //the speed of the camera movement
        	public Transform target;
    	void Start () {
    		target = transform;
        void LateUpdate () {
        	transform.position = Vector3.Lerp (transform.position, target.position, time.DeltaTime * cameraSpeed);

And that’s it!

Good luck. Let me know if this works for you.