Only 2 linesbut cannot work

On 2 lines code,like this:

function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
}

But,I got error:“NullReferenceException: Object reference not set to an instance of an object”

I don’t know why。help me。Thanx。

I guess you have no camera tagged MainCamera.

–Eric

No,In my scence only 2 object:One is a cube, another is the camera with a default name MainCamera.

I’m not talking about the name, I’m talking about the tag. Camera.main finds the first object tagged “MainCamera”; it doesn’t care what it’s named. If there’s no object tagged “MainCamera”, it won’t find anything.

–Eric

thank a lot!