Hey guys
sorry if this is a really basic question. So i got this C# script to smoothly transition between camera positions through key-Inputs (see below) with linear interpolation (the different ‘views’ are empty game objects where the camera should go and the script is attached to the camera.
But now when i try to run it, there is a NullReferenceException (‘Object reference not set to an instance of an object’)…
Problem is I can’t really tell whats wrong with my script (see below)…
Any suggestions where the problem could be?
Many thanks in advance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl: MonoBehaviour {
public Transform [] views;
public float transitionSpeed;
Transform currentView;
//initialisation
void Start ()
{
}
void Update() {
if (Input.GetKeyDown ("q")) {
currentView = views [0];
}
if (Input.GetKeyDown ("e")) {
currentView = views [1];
}
if (Input.GetKeyDown ("r")) {
currentView = views [2];
}
}
void LateUpdate () {
//Lerp position
transform.position = Vector3.Lerp(transform.position, currentView.position, Time.deltaTime * transitionSpeed);
//get the angles as well
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;
}
}