Center camera on object in unity3d by programatically

i wanted to center my camera on object once they are turn is active… But, i am unable to do it.

Here is my code:

public GameObject UserPlayerPrefab;
public Vector3 v3;
 
void Update()
    {
        transform.LookAt(UserPlayerPrefab.transform.position);
    }

when i tried the above code, the result is like this:

Where when i not applied transform.LookAt(UserPlayerPrefab.transform.position), the result is like this (camera modified by manually in the design view)

What i want is the camera centered on the player whenever it is turn and the camera follows the object whenever he go until the turn ended, and move to the next player.

Note: I using List to create multiple spheres and multiple cylinder. In the design view, i only got 1 sphere and 1 cylinder and 1 box of the terrain.

I think the problem may be you’re focusing it on the position, and transform.LookAt() takes a transform not a vector3

so try this instead and get back to me

transform.LookAt(UserPlayerPrefab.transform);

if that doesn’t work, then is the camera a child to anything? if so, then try making it independent and without a parent

Sorry for late reply, i already solve that question,

contains many children inside it. So the camera doesn’t know which player has to focus on. So i changed to

But, the result is not as i expected, and seems weird.

Here is the result:

Before i change the

to

, the camera is centered and back behind the player (third person camera), but once i applied above code, the result is like the image shown above (Capture.png).

And when i move the player, here is the result (notice the camera movement):