C# Unity 3D:未应用相机背景色

C# Unity 3D:未应用相机背景色,c#,unity3d,google-cardboard,C#,Unity3d,Google Cardboard,在我的3D谷歌纸板VR迷你游戏中,在切换到另一个场景之前,我想将当前场景的背景淡入白色,以获得良好的过渡效果 我构建了一个函数,可以在2秒内将颜色值从黄色更改为白色: within Update (): if (started) { if (startTime >= startDelay) { //start } else { //fade thisBrightness = startTime / 2; // runs 2 seconds if (

在我的3D谷歌纸板VR迷你游戏中,在切换到另一个场景之前,我想将当前场景的背景淡入白色,以获得良好的过渡效果

我构建了一个函数,可以在2秒内将颜色值从黄色更改为白色:

within Update ():

if (started) {
  if (startTime >= startDelay) {
    //start
  } else {
    //fade
    thisBrightness = startTime / 2; // runs 2 seconds
    if (thisBrightness > 1) {
      thisBrightness = 1; // just in case
    }
    Camera.main.backgroundColor = Color.Lerp (mainCameraBackground, mainCameraFaded, thisBrightness);
    startTime += Time.deltaTime;
  }
}
我记录了浮动“thisBrightness”,它从0变为1。此外,我可以在检查器中看到“摄影机>背景”中的颜色字段发生了变化,但在我的游戏预览中,它没有发生变化-颜色保持不变

有人对此有任何解释和解决办法吗??! 1000谢谢

费利克斯

Unity 5.5.0f3个人电脑
谷歌硬纸板1.0编辑:我刚回到这个问题,发现它并没有得到真正的回答。 我发现,主摄像头被谷歌VR SDK转换为左+右独立摄像头

您需要分别处理这两个问题,请参见下面的代码,例如我最终是如何解决这一问题的:

public Camera leftCamera;
public Camera rightCamera;

mainCameraBackground = new Color (1, 0.8f, 0); // set to yellow initially
mainCameraFaded = new Color(1f,1f,1f);
mainCameraCurrent = new Color (0f, 0f, 0f);

// main camera is converted to left + right by Google VR SDK.
// this is why we need to handle both separately

leftCamera.clearFlags = CameraClearFlags.SolidColor;
leftCamera.backgroundColor = mainCameraBackground;

rightCamera.clearFlags = CameraClearFlags.SolidColor;
rightCamera.backgroundColor = mainCameraBackground;
然后:

mainCameraCurrent = Color.Lerp (mainCameraBackground, mainCameraFaded, thisBrightness);
rightCamera.backgroundColor = mainCameraCurrent;
leftCamera.backgroundColor = mainCameraCurrent;

至少,现在我找到了解释:在运行时,GoogleCardwardSDK添加了两个新摄像头(左+右)作为主摄像头的子摄像头。现在我必须想办法改变它们的背景色;)嗨,如果你找到了问题的答案,请把它贴出来。这不是你问题的答案。您可以编辑它并扩展您的答案。@程序员希望这足够了,这样更好。不要只发布一个链接,因为链接可能会随时消失,使你的答案毫无用处+1.