0

I am trying to toggle between the Solid Color clear flag and the skybox clear flag with a button press. This is so I can switch between passthrough AR and VR mode. Currently I have a script running which toggles on the passthrough, but by default the passthrough requires the clear flags solid color to be selected,

so I have written a second script which changes the camera flags from solid color to skybox, unfortunately this only works one direction and I cannot figure out how toggle the skybox back to solid color. I know this is a rudimentary problem.

`

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.ARFoundation;

public class BackgroundChange : MonoBehaviour
{
[SerializeField]
private InputActionProperty toggleAction;

private Camera targetCamera;

private void Awake()
{
    toggleAction.action.Enable();
    targetCamera = FindAnyObjectByType<Camera>();
}

private void OnTogglePerformed(InputAction.CallbackContext obj)
{
if (targetCamera == null)
{
    
    targetCamera = Camera.main;
}

targetCamera.clearFlags = CameraClearFlags.Skybox;
}

private void OnEnable() => toggleAction.action.performed += OnTogglePerformed;

private void OnDisable() => toggleAction.action.performed -= OnTogglePerformed;
}`

This the script for toggling to the skybox from the solid color, It seems to only be one way.

  • Just a guess but maybe you need to clear the buffer somehow, perhaps https://docs.unity3d.com/ScriptReference/Camera.Reset.html – Absinthe Aug 11 '23 at 19:18

0 Answers0