Где-то хранится исходное положение и поворот cube
Vector3 origPosition = cube.transform.position;
Quaternion origRotation = cube.transform.rotation;
Получить значения смещения между кубом и треугольником
Vector3 posOffset = triangle.transform.position - cube.transform.position;
Quaternion rotOffset = Quaternion.Inverse(cube.transform.rotation) * triangle.transform.rotation;
(Re) Установить куб и треугольник на место
cube.transform.position = origPosition;
cube.transform.rotation = origRotation;
triangle.transform.position = origPosition + posOffset;
triangle.transform.rotation = origRotation * rotOffset;
Пример
public class CubeMover : MonoBehaviour
{
public Transform cube;
public Transform triangle;
private Vector3 origPosition;
private Quaternion origRotation;
// Start is called before the first frame update
private void Start()
{
origPosition = cube.transform.position;
origRotation = cube.transform.rotation;
}
[ContextMenu("Test")]
public void ResetCube()
{
Vector3 posOffset = triangle.transform.position - cube.transform.position;
Quaternion rotOffset = Quaternion.Inverse(cube.transform.rotation) * triangle.transform.rotation;
cube.transform.position = origPosition;
cube.transform.rotation = origRotation;
triangle.transform.position = origPosition + posOffset;
triangle.transform.rotation = origRotation * rotOffset;
}
}
(Треугольника не было, поэтому я использовал Цилиндр ... Надеюсь, это хорошо для вас ^^)
