相机似乎只能在其中两个相机之间工作,并且不会像预期的那样切换回其他相机。因为我是新手,所以可能做一些愚蠢的事情。非常感谢。
using UnityEngine;
public class CameraController : MonoBehaviour
{
这是场景中的主摄像机。
public Camera MainCamera;
这些是场景中的其他摄像机。
public Camera FrontCamera;
public Camera LeftCamera;
public Camera RightCamera;
public Camera BackCamera;
功能
void Start()
{
MainCamera = Camera.main;
MainCamera.enabled = true;
FrontCamera.enabled = false;
LeftCamera.enabled = false;
RightCamera.enabled = false;
BackCamera.enabled = false;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
if (MainCamera.enabled)
{
FrontCamera.enabled = true;
MainCamera.enabled = false;
LeftCamera.enabled = false;
RightCamera.enabled = false;
BackCamera.enabled = false;
}
else if (Input.GetKeyDown(KeyCode.Space))
if (FrontCamera.enabled)
{
LeftCamera.enabled = true;
FrontCamera.enabled = false;
}
此刻代码可以正常工作。
else if (Input.GetKeyDown(KeyCode.Space))
{
if (LeftCamera.enabled)
{
RightCamera.enabled = true;
LeftCamera.enabled = false;
}
}
else if (Input.GetKeyDown(KeyCode.Space))
{
if (RightCamera.enabled)
{
BackCamera.enabled = true;
RightCamera.enabled = false;
}
}
else if (Input.GetKeyDown(KeyCode.Space))
{
if (BackCamera.enabled)
{
MainCamera.enabled = true;
RightCamera.enabled = false;
}
}
else if (Input.GetKeyDown(KeyCode.Space))
if (!MainCamera.enabled) ;
{
MainCamera.enabled = true;
}
}
}
答案 0 :(得分:0)
选项卡和方括号令人困惑。另外,嵌套的if,if else-if else-ifs的结构令人困惑。您的最后一条语句基本上是空的:
DECLARE @LocationID DATATYPE
SET @LOCATION ID = VALUE
相反,设置代码结构以对按空格键作出反应,然后检查摄像头系统的状态:
else if (Input.GetKeyDown(KeyCode.Space))
if (!MainCamera.enabled) ;
{
MainCamera.enabled = true;
}