change camera's view toward different targets

hey,
so im trying to use this script i found on youtube it’s about cameras changing position and rotation toward multiple targets . so i watched the video it was exactly what i needed. but the problem is when i attach the script to my camera and assign some empty game objects as targets and hit play the game freezes.
its giving me NullReferenceException errorenter code here
i don’t know where the problem is :frowning:
hope you guys could help me
and here is the video; - YouTube
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class smoothcameratransition : MonoBehaviour {
	public Transform[] views;
	public float transitionSpeed; 
	Transform currentView;

	// Use this for initialization
	void Start () { }

	void Update(){

		if (Input.GetKeyDown (KeyCode.Alpha1)) 
			currentView = views [0];
		

		if (Input.GetKeyDown (KeyCode.Alpha2)) 
			currentView = views [1];
		}



	 void LateUpdate () {

		//Lerp position
		transform.position = Vector3.Lerp(transform.position, currentView.position, Time.deltaTime * transitionSpeed);

		Vector3 currentAngle = new Vector3 (
			Mathf.LerpAngle(transform.rotation.eulerAngles.x, currentView.transform.rotation.eulerAngles.x, Time.deltaTime * transitionSpeed),
			Mathf.LerpAngle(transform.rotation.eulerAngles.y, currentView.transform.rotation.eulerAngles.y, Time.deltaTime * transitionSpeed),
			Mathf.LerpAngle(transform.rotation.eulerAngles.z, currentView.transform.rotation.eulerAngles.z, Time.deltaTime * transitionSpeed));

		transform.eulerAngles = currentAngle;

	}
}

public Transform views;

This is a variable that you can define in the inspector of the object. To use the code you posted without error, you MUST have at least 2 views populated in there.

This is because:

If you have a zero size for the array ‘views’ will NOT be a valid array, so obviously views [0]` will NOT be a valid value.

If you have only one element in the array views [1]` will NOT be a valid value.

It is good practice to check or otherwise ensure the variables you want to access are valid, for exactly this reason (missing data should not generate some unspecific error like that).
for example:

if(views!=null && views.Length>=2)
   //do your normal ops.
else
   Debug.Log("you dont have any/enough views specified in the smoothcameratransition component of object : "+name+"  So, I'm not doing anything.");