Object reference not set to an instance of an object [problem with Unity 5]

Hi to all… I imported a project that i’ve made with unity 3 and there wasn’t errors, when I import the project in Unity 5 this script give me this error: Object reference not set to an instance of an object… Why in Unity 3 I don’t have this problem? :frowning:
The line where ther’s the error is ray = Camera.main.ScreenPointToRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
Hope someone can help me. :slight_smile:

Here the full script

 private var decrement : float;
    private var toggle : boolean;
    private var ray : Ray;
    private var hitInfo : RaycastHit;
    
    
    var Audio : AudioClip;
     
    function Start()
    {
    	decrement = transform.localScale.y / 1.3f; //modificare questo valore per ridurre l'altezza.
    } 
     
    function OnMouseDown()
    {   
    
    if(!enabled) return;
    
        ray = Camera.main.ScreenPointToRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
    
    	if(Physics.Raycast(ray, hitInfo))
    	{
    		if(hitInfo.transform.gameObject == gameObject)
    		{
    			if(Input.GetMouseButton)
    		    {
    				if(!toggle)
    				{
    					transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y - decrement, transform.localScale.z);
    					transform.position.y += decrement / 2;
    					toggle = true;
    					GetComponent.<AudioSource>().clip = Audio;
                        GetComponent.<AudioSource>().Play();
    				}
    
    				else
    				{
    					transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y + decrement, transform.localScale.z);
    					transform.position.y -= decrement / 2;
    					toggle = false;
    					GetComponent.<AudioSource>().clip = Audio;
                        GetComponent.<AudioSource>().Play();
    				}
    			}
    		}
        }
    }

Object reference not set to an instance of an object generally means you haven’t dragged and dropped a gameobject in the inspector.

Either your scene does not have a Camera, OR that camera is not tagged as “Main Camera”. At least that’s the only object in that code line that might be not found.