I'm getting this error but I have no clue whats wrong with my code. I am not getting any compile errors, but errors when I start the game. The error is:
NullReferenceException: Object reference not set to an instance of an object
PlayerCamera.CameraMovement () (at Assets/Scripts/PlayerCamera.cs:185)
PlayerCamera.LateUpdate () (at Assets/Scripts/PlayerCamera.cs:141)
Here is the code that gives me the error:
public void CameraMovement()
{
if (playerController.aim)
{
Camera.main.fieldOfView = Mathf.Lerp (Camera.main.fieldOfView, zoomFOV, _deltaTime * lerpSpeed);
_camDir = (aimDirection.x * target.forward) + (aimDirection.z * target.right);
_targetHeight = normalAimHeight;
_targetDistance = normalAimDistance;
}
else
{
Camera.main.fieldOfView = Mathf.Lerp (Camera.main.fieldOfView, normalFOV, _deltaTime * lerpSpeed); //Error on this line
_camDir = (normalDirection.x * target.forward) + (normalDirection.z * target.right);
_targetHeight = normalHeight;
_targetDistance = normalDistance;
}
↧