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
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 :,)