Je viens de suivre et reproduire exactement un vieux tuto sur YouTube mais j'ai une erreur et je ne comprend pas ce que c'est.
Je n'est pas touché à Unity depuis longtemps j'ai peut-être manqué quelque chose d'évident.
Pourriez vous me dire ce qui ne va pas.
Merci
NullReferenceException: Object reference not set to an instance of an object
CameraController.LateUpdate () (at Assets/CameraController.cs:45)
Voici le script que j'ai reproduit à l'identique:
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : 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];
}
if (Input.GetKeyDown (KeyCode.Alpha3)) {
currentView = views [2];
}
if (Input.GetKeyDown (KeyCode.Alpha4)) {
currentView = views [3];
}
if (Input.GetKeyDown (KeyCode.Alpha5)) {
currentView = views [4];
}
}
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;
}
}