How can I make a raycast move towards an object?

I want to detect if a wall is between two objects. How do I project a raycast towards an object?

Vector3 dir = otherObject.transform.position - transform.position;
if (Physics.Raycast(transform.position, dir, dir.magnitude))