Raycast problem - NullReferenceE1xception

i have this:

using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour
{
	public float speed;
	public CharacterController controller;
	private Vector3 position;

	public AnimationClip idle;
	public AnimationClip run;

	public static bool attack;
	public static bool die;

	// Use this for initialization
	void Start ()
	{
		position = transform.position;
	}
	
	// Update is called once per frame
	void Update ()
	{
		if(!attack && !die)
		{
			if (Input.GetMouseButton (0))
			{
				locatePosition();
			}

			moveToPosition();
		}
	}

	void locatePosition()
	{
		RaycastHit hit;
		Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);

		if(Physics.Raycast(ray, out hit, 1000))
		{
			if(hit.collider.tag!="Player" && hit.collider.tag!="Enemy")
			{
				position = hit.point;
			}
		}
	}

	void moveToPosition()
	{
		if(Vector3.Distance(transform.position, position)>0.4)
		{
			Quaternion newRotation = Quaternion.LookRotation(position-transform.position);

			newRotation.x = 0f;
			newRotation.z = 0f;

			transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 15);
		
			controller.SimpleMove (transform.forward * speed);
			animation.CrossFade(run.name);
		}
		else
		{
			animation.CrossFade(idle.name);
		}
	}
}

It was good, but today i must move my project, so i moved it, i set up my plugins again but now i have this error:
NullReferenceException: Object reference not set to an instance of an object
Move.locatePosition () (at Assets/Scripts/Move.cs:39)
Move.Update () (at Assets/Scripts/Move.cs:29)
;/

I’m not sure if the line numbers match between your file and this, but I’m assuming that it’s this line:

if(hit.collider.tag != "Player" && hit.collider.tag != "Enemy")

You are attempting to access hit.collider even thought there is no guarantee that your raycast hit anything, so hit.collider could be null. Thankfully it’s a very easy problem to fix, you just need to check that hit.collider is not null:

if(hit.collider != null && hit.collider.tag != "Player" && hit.collider.tag != "Enemy")

This is quite a common problem.

Possibly the tag of the camera “main” got modified. Check if the “main” camera has the proper tag.