You can store your current pivot object, direction from it, and distance away in member variables.
Overwrite these values when you start rotating around a new pivot, but then keep the distance variable fixed at that value for future updates.
In your Update (or LateUpdate, if you want to be sure this runs after any Update scripts or animations that move your pivot objects around), rotate your direction, scale it by your distance, and add it to the pivot position to find your new location relative to it.
Here’s one way that could look:
public class RotateAround : MonoBehaviour {
public float rotationSpeed = 90f;
Transform _pivot;
Vector3 _offsetDirection;
float _distance;
public void SetPivot(Transform pivot) {
if (pivot != null) {
_pivot = pivot;
_offsetDirection = transform.position - pivot.position;
_distance = _offsetDirection.magnitude;
} else {
_pivot = null;
}
}
void Update() {
if (_pivot == null) return;
Quaternion rotate = Quaternion.Euler(0, 0, rotationSpeed * Time.deltaTime);
_offsetDirection = (rotate * _offsetDirection).normalized;
transform.position = _pivot.position + _offset * _distance;
}
}