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
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;
}
}