An instance of type 'UnityEngine.GameObject' is required to access non static member 'transform'?

I don’t understand this error because a similar script worked and this one doesn’t.

#pragma strict

function Update () 
{
	if (Input.GetKey ("e"))
	{
		var ray : Ray = Camera.main.ViewportPointToRay (Vector3(0.5, 0.5, 0));
		
		var hit : RaycastHit;
		
		if (Physics.Raycast (ray, hit))
		{
			hit.transform.SendMessage ("PickUpObject", SendMessageOptions.DontRequireReceiver);
		}
	}
}

I don’t think RaycastHit derives from GameObject. It’s just a data structure, so it won’t have a Transform component. You also don’t need the “.transform” there, SendMessage is a method of GameObject.

Your SendMessage line probably needs to be :

hit.collider.SendMessage (“PickUpObject”, SendMessageOptions.DontRequireReceiver);