How to make camera follow player after a short period of time.

I already have a camera script which makes the camera follow the player (the player is a spaceship by the way) and it works pretty good. However, for my game, I would like the camera to follow the player like it does right now, but I would also like the camera to start following the player after a short period of time.

Here’s what I mean: Let’s say that we have a public float variable named delay. Once the player starts moving, the camera should wait for a specific amount of time which is defined by delay and then start following the player the way it already does.

Here’s the whole camera script I already have:

using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {
	public GameObject player;
	private Vector3 offset;
	
	void Start () {
		offset = transform.position;
	}

	void LateUpdate () {
		if (player != null) {
			transform.position = player.transform.position + offset;
		}
	}
}

So how am I supposed to do that?

You’ll be wanting to use a Coroutine for that.

Use Time.time , like you could have 2 veriables, one to set as the time to wait and the other to equal Time.time plus the delay so… a bit like this :

public class CameraController : MonoBehaviour {

public GameObject player;
private Vector3 offset;
Public float delay = 2f; //For example here it waits 2 seconds.
Public float followNow;

Void Start()
{
    followNow = Time.time + delay;
}

Void Update ()
{
    if (Time.time > followNow)
    {
        Offset = transform.position;
    }
}
 
Void LateUpdate ()
{
    if (player != null) {
      transform.position = player.transform.position + offset;
    }
}

}

This is just my idea but I’m not entirely sure it will work, hope it does though.