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? :( 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. :)
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();
                     }
                 }
             }
         }
     }
     
 
              Could someone help me? I don't know how to fix this problem
Answer by hexagonius · Oct 31, 2015 at 11:32 AM
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.
Answer by Tom01098 · Oct 31, 2015 at 11:24 AM
Object reference not set to an instance of an object generally means you haven't dragged and dropped a gameobject in the inspector.
Your answer