camera position.

I am making a football penalty kind of game. SO everytime ball goes out of the boundary i am respawning it to some random position. Now i want my camera to face the goal and the ball should also be in centre,

I am using transform.LookAt(goal.transform.position);

It is always facing the goal but the ball is randomly changing its position.

//Camera position
transform.position = new Vector3( ball.transform.position.x, ball.transform.position.y + 0.77f, ball.transform.position.z - 3f);
		
//Camera rotating towards goal
transform.LookAt(goalPost.transform.position );

I think you are asking for the ball to be centered between the camera and the goal. To do that, generate a vector from the goal to the ball. Double it, and then add it back to the goal position. Untested code:

Vector3 v3Pos = ball.transform.position - goalPost.transform.position;
transform.position = v3Pos * 2.0f + goalPost.transform.position;