Can't get and keep the old position of my camera to re-use later

In my game, I have one button that saves the transform of the player’s camera in the remember var, then changes the player cam’s transform. Then, there is another button that is supposed to reset the cam’s transform to its old transform through the remember var.

The problem is that the remember var sets to the player cam’s transform after it moves :confused:

Here is the code:

public GameObject playerCamera;
Transform rememberPlayerCameraPos;

public bool isBuilding = false;

private void Awake()
{

    rememberPlayerCameraPos = transform;

}

private void Update()
{
    if (isBuilding == true)
    {
    }
}

public void StartBuilding()
{
    //Lock Camera
    if (isBuilding != true)
    {
        rememberPlayerCameraPos = playerCamera.transform;
    }

    playerCamera.transform.position = new Vector3(0f, 10f, 0f);
    playerCamera.transform.rotation = Quaternion.Euler(90f, 0f, 0f);

    isBuilding = true;
}

public void StopBuilding()
{
    playerCamera.transform.position = rememberPlayerCameraPos.position;
    playerCamera.transform.rotation = rememberPlayerCameraPos.rotation;

    isBuilding = false;
}

I’m on a very short deadline so please help me :,)

I would check somethings, first of all, change awake to start and see if it helps. then maybe your camera is child, and you need to save and paste localpositions? i dont clearly get the question too. is the camera taking time to get back to remembered pos?

Hi, I think transform is a reference type so you can’t make a copy by assigning with ‘=’.

Instead, try storing the position and rotation eg:

Vector3 rememberPosition = playerCamera.transform.position;
Quarternion rememberRotation = playerCamera.transform.rotation;