Reset 3D Model Rotation to it's Initial position

I have made a scene of 3D models in which i am switching between different cameras set at different 3D models, the user can rotate the 3D models and navigate to next or previous model using navigation button.

I am facing a tiny problem, i want the rotation of 3D model to be reset to its initial (original) rotation coordinates when the user click on the next or previous model button, so that if the user comes back to that model which he rotated, he finds it in it the initial position.

The scene contains cameras in which there is a game object and inside the game object i have my 3D model. The rotation script is applied on the game object and not on the model. So for each model hierarchy is this: Camera → gameobject (rotate script applied) → 3D model

Also for camera switching there is a separate game object on which i have applied CameraSwitcher.cs script. Inside that game object i have added all the cameras as the array elements inside Cameras property

The UI consists of the Canvas->Panel-> Button1(Previous), Button2(Next). On these buttons i have attached OnClick property to CameraSwitcher previous and next functions respectively.

This is the cameraswitcher script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraSwitcher : MonoBehaviour
{
    public List<Camera> cameras;
    private int currentCameraIndex = 0;
    void Start()
    {
        // Ensure the initial camera is active, and the others are inactive
        for (int i = 0; i < cameras.Count; i++)
        {
            cameras[i].gameObject.SetActive(i == 0);
        }
        
    }

    public void SwitchCamera(int direction)
    {
        // Disable the current camera
        cameras[currentCameraIndex].gameObject.SetActive(false);
        // Calculate the new camera index
        currentCameraIndex += direction;
        // Wrap around the camera index
        if (currentCameraIndex < 0)
        {
            currentCameraIndex = cameras.Count - 1;
        }
        else if (currentCameraIndex >= cameras.Count)
        {
            currentCameraIndex = 0;
        }

        // Enable the new camera
        cameras[currentCameraIndex].gameObject.SetActive(true);

    }
    public void SwitchToNextCamera()
    {
        SwitchCamera(1);
    }
    public void SwitchToPreviousCamera()
    {
        SwitchCamera(-1);
    }
}

This is my UI:


(Ignore the back button and search button)

Kindly help me, i am beginner and need help with college my project… I dont know how to achieve this, i have tried but failed…

You can achieve this by giving your RotateScript a field of type Quaternion then store the initial rotation inside the Awake() method.
Then, in your CameraSwitcher component, when you switch to a different camera, fetch the RotateScript that’s in the camera’s hierarchy and tell it that you’re switching to the model’s camera or switching away from it.
When the RotateScript is told that the camera has switched, it should restore the rotation.

NOTE: I’m away from Unity for about a day, so I haven’t tested the code, but it should be clear what I’m trying to do.

RotateScript component

public class RotateScript : MonoBehaviour
{
    private Quaternion storedLocalRotation;

    private void Awake ()
    {
        // Store the object's initial rotation
        StoreCurrentRotation();
    }

    public void StoreCurrentRotation ()
    {
        storedLocalRotation = transform.localRotation;
    }

    public void ResetRotation ()
    {
        transform.localRotation = storedLocalRotation;
    }

    public void OnSwitchingToThisModel ()
    {
        ResetRotation();
    }

    public void OnSwitchingAwayFromThisModel ()
    {
        ResetRotation();
    }
}



CameraSwitcher component:

public class CameraSwitcher : MonoBehaviour
{
    public void SwitchCamera (int direction) 
    {
        var oldCamera = GetCamera(currentCameraIndex);
        var newCamera = GetCamera(currentCameraIndex + direction);

        // Disable the old camera
        // and notify the RotateScript
        oldCamera.gameObject.SetActive(false);
        NotifyRotateScriptOfSwitchAwayFromCamera(oldCamera);

        // Enable the new camera
        // and notify the RotateScript
        newCamera.gameObject.SetActive(true);
        NotifyRotateScriptOfSwitchToCamera(newCamera);
    }

    public Camera GetCamera (int index)
    {
        if (cameras.Count == 0)
            return null;
        if (index < 0) index = cameras.Count - 1; else
        if (index >= cameras.Count) index = 0;
        return cameras[index];
    }

    public void NotifyRotateScriptOfSwitchToCamera (Camera cameraToSwitchTo)
    {
        // Notify the RotateScript that its model is about to be viewed
        GetRotateScript(cameraToSwitchTo)?.OnSwitchingToThisModel();
    }

    public void NotifyRotateScriptOfSwitchAwayFromCamera (Camera cameraToSwitchAwayFrom)
    {
        // Notify the RotateScript that its model is no longer being viewed
        GetRotateScript(cameraToSwitchAwayFrom)?.OnSwitchingAwayFromThisModel()
    }

    public RotateScript GetRotateScript (Camera camera)
    {
        // Gets the RotateScript that belongs to a specific camera
        return camera?.GetComponentInChildren<RotateScript>();
    }
}

If you’re not used to the questionmark I’m using in the code, you can read about it here: