Trying to just move an object along the X axis using the mouse screen position. For some reason the Input.mousePosition doesn’t return a variable so I can’t just use it to do a transform. All the other languages I’ve used I can do this in 2 minutes.
public Transform objectToMove;
void Start () {
Cursor.visible = false;
}
void Update () {
Vector3 mouse = Input.mousePosition;
Ray castPoint = Camera.main.ScreenPointToRay(mouse);
RaycastHit hit;
if (Physics.Raycast(castPoint, out hit, Mathf.Infinity))
{
objectToMove.transform.position = hit.point;
}
}
}
This moves the object toward the camera and locking the y and z in Rigidbody has no effect