NullReferenceException in a simple code....

Hi everyone… I’m trying to put a sprite on the topleft corner of the camera (without concerning about the resolution…) so I’ve wrote this very simple script:

function Update () { 	
			this.transform.position = Camera.current.ScreenToWorldPoint (Vector3(0, Camera.current.pixelHeight, 10));

This script works very well but the console is returning me thousand times this error:

NullReferenceException: Object reference not set to an instance of an object

what can I do? I’ve tried a search but I really don’t understand my problem now…

Thanks to all!

I think you have to use Camera.main instead of Camera.current

Ok, finally I managed it! I’ve inserted a reference to the main camera as var in the script and it works!

Here is the new working script:

var cameraReference: Camera;

function Start () {

function Update () {

						this.transform.position = cameraReference.ScreenToWorldPoint (Vector3(0, cameraReference.pixelHeight, 10));

No more alert in the console!!! :smiley:

Thanks to all!!!