weird NullReferenceException

Every frame I get this error:

NullReferenceException: Object reference not set to an instance of an object
LookAt2D.Update () (at Assets/Scripts/LookAt2D.cs:8)

From this script:

using UnityEngine;
using System.Collections;

public class LookAt2D : MonoBehaviour {

	void Update(){

		Vector3 mousePosition = (Camera.current.ScreenToWorldPoint(Input.mousePosition));
		mousePosition.z = transform.position.z;
		transform.LookAt(mousePosition);

	}
}

And I don’t really know why. Any suggestions?

Camera.current is probably null… Read the docs :wink: This should only be used in a few events (Update not being one of them). As also stated in the docs, you most likely want to use Camera.main instead.