【问题标题】:Unity 3D: Camera Background Color not applyingUnity 3D:相机背景颜色不适用
【发布时间】:2017-01-15 16:59:52
【问题描述】:

在我的 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。此外,我可以在 inspector 中看到 Camera > Background 中的颜色字段发生了变化,但在我的 Game Preview 中却没有 - 颜色保持不变。

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

菲利克斯

Unity 5.5.0f3 个人版 谷歌纸板 1.0

【问题讨论】:

  • 至少,现在我找到了解释:在运行时,Google Cardboard SDK 添加了 2 个新相机(左 + 右)作为主相机的子相机。现在我必须想办法改变它们的背景颜色;)

标签: c# unity3d google-cardboard


【解决方案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;

【讨论】:

  • 您好,如果您找到问题,请发布解决方案。这不是您问题的解决方案。您可以对其进行编辑并扩展您的答案。
  • @Programmer 希望这就足够了
  • 是的,这样更好。不要仅使用链接发布答案,因为链接可能随时消失,使您的答案无用。 +1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-15
  • 2013-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多