需要更改相机视图



我用不同的按钮做到了这一点,但我只想使用一个

这是我的代码:

public GameObject cam1;
public GameObject cam2;
void Start()
{

}
// Update is called once per frame
void Update()
{


if (Input.GetButtonDown("Switch1"))
{
cam1.SetActive(true);
cam2.SetActive(false);


}
if (Input.GetButtonDown("Switch2"))
{
cam1.SetActive(false);
cam2.SetActive(true);

}


}

顺便说一句。我在联合工作

如果相机一处于活动状态,使用一个bool来存储如何。按下该键时,如果为true,则将其设置为false,反之亦然,然后更新相机。

public GameObject cam1;
public GameObject cam2;
private bool cam1Active = true;
void Start()
{

}
// Update is called once per frame
void Update()
{

if (Input.GetButtonDown("Switch1"))
{
cam1Active = !cam1Active;
cam1.SetActive(cam1Active);
cam2.SetActive(!cam1Active);
}

}

最新更新