Unity 5 Input.mousePosition NullReferenceException

Hello, I used this code in Unity 4 to rotate my player to the mouse position with a top view camera. But when i updated to Unity 5 it stopped working leaving me with a NullReferenceException error both in Javascript and C#

What would have to be modified so it works in Unity 5? Sorry for my bad English

 var speed = 4.0;
  function Update () {
      var playerPlane = new Plane(Vector3.up, transform.position);
      var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
      var hitdist = 0.0;
      if (playerPlane.Raycast (ray, hitdist)) {
          var targetPoint = ray.GetPoint(hitdist);
          var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
          transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);

I am not a coding expert but you might need to change function Update () { to void Update () {. I hope it helps.