Ez code to fix camera to base

for those who are having difficult with getting thier camera fix to base when joined as client …here is simple way to do it …
in your unitbase script add these line

public static event Action clientOnBaseSpawned;
public override void OnStartClient()
{
if (!isOwned) { return; }
clinetOnBaseSpawned?.Invoke(this);
}

and then in camera controller add these line

public override void OnStartClient()
{
    UnitBase.clientOnBaseSpawned += clientHandleBaseSpawned;
}
public override void OnStopClient()
{
    UnitBase.clientOnBaseSpawned -= clientHandleBaseSpawned;
}
private void clientHandleBaseSpawned(UnitBase unitbase)
{
    playerCameraTransform.position = new Vector3(unitbase.transform.position.x, playerCameraTransform.position.y, unitbase.transform.position.z);
       
}
1 Like

Hi,

What I did is instead of

playerCameraTransform.position = new Vector3(unitbase.transform.position.x, playerCameraTransform.position.y, unitbase.transform.position.z);

I change unitbase.transform.position.z

to

playerCameraTransform.position = new Vector3(unitBase.transform.position.x, playerCameraTransform.position.y, playerCameraTransform.position.z);

on my camera transform I adjust the Z postion to my desired starting point

1 Like

Privacy & Terms