-
We can add object in Unit with required position
-
Add new property to ShootAction:
[field: SerializeField] public Transform ActionCameraPosition { get; private set; } -
And CameraManager will looks like that:
case ShootAction shootAction:
_actionCamera.transform.parent = shootAction.ActionCameraPosition;
_actionCamera.transform.localPosition = Vector3.zero;
_actionCamera.transform.localRotation = Quaternion.identity;
ShowActionCamera();
break;
Yup that’s another great way to do it.
I probably wouldn’t change the parent, you might forget to unparent and if the Unit dies you could end up accidentally destroying the actionCamera.
So you could just set the actionCamera.transform.position = shootAction.ActionCameraPosition.position; and rotation
Actially setting a parent is a must.
I’ve ran into the weird camera behaviour and the reason is the order of position calculation: OnAnyActionStarted fired → set a position to ActionCamera.
But after you set this the Unit can still rotate to the target and the actionCamera.position is not valid anymore. So after OnAnyActionStarted you need to monitor the state (Aiming-Shooting) of the action and set it only after aiming is done or, much simpler, set a parent which will handle all of that and even make a cool effect of following Unit’s rotation while aiming.