Unity 3D:相机背景颜色不适用

时间:2017-01-15 16:59:53

标签: c# unity3d google-cardboard

在我的3D Google Cardboard 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。另外,我可以在检查器中看到相机中的颜色字段>背景改变,但在我的游戏预览中,它没有 - 颜色保持不变。

enter image description here

有人对此有任何解释和解决方案吗? 1000谢谢!

菲利克斯

Unity 5.5.0f3个人版 Google Cardboard 1.0

1 个答案:

答案 0 :(得分:1)

编辑:我刚回到这个问题,发现它没有真正回答。 我发现Google 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;