How to set a raycast as a hit.

Ray ray = Camera.mainCamera.ScreenPointToRay( Input.mousePosition );
RaycastHit hit;
target = hit.transform;

Is returning error CS0165: Use of unassigned local variable `hit’
Am I not assigning the raycast to the hit?!?! whats the problem?!

Ray ray = Camera.mainCamera.ScreenPointToRay( Input.mousePosition );
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, 2f) // this is for C#
if(hit.gameObject.name == “Player”){ // the gameObject’s name you wanna hit
target = hit.transform;
}

You are missing the actual raycast itself here.
link text

Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, 100)) {
    target = hit.collider.gameObject;
}