- Home /
How do I make cam switching on one Input?
Currently Im working on camera switching. What I think it should be, is switching bool. For example when I press f5 and isReady is true, one cam goes off and second on and with it switches bool isReady. And when I press f5 and isReady is false, one cam goes on and second off and again isReady goes true. At first it wasnt working, then I realized, it all happens at the same time. So i added IEnumerator (or what that is). And there comes the part, where I dont know what the hell is happening. So there is my code:
void Update {
//Cam switch
if(Input.GetButtonDown("Cam Switch") && isCam1On)
{
cam1.enabled = false;
cam2.enabled = true;
StartCoroutine(CamChanger(isCam1On));
}
if(Input.GetButtonDown("Cam Switch") && !isCam1On)
{
cam1.enabled = true;
cam2.enabled = false;
StartCoroutine(CamChanger(isCam1On));
}
if (!isCam1On) isCam2On = true;
if (!isCam2On) isCam1On = true;
//Cam Switch\\
}
//Cam Switch
IEnumerator CamChanger(bool _isCamOn)
{
yield return new WaitForSeconds(2);
_isCamOn = !_isCamOn;
}
//Cam Switch\\
Answer by Hellium · May 06, 2020 at 11:15 AM
Why making things so complicated?
void Update
{
if(Input.GetButtonDown("Cam Switch"))
{
cam1.enabled = !cam1.enabled;
cam2.enabled = !cam2.enabled;
}
}
Ah. Well. Now Im embarrassed. Thanks a lot! Have a nice day.
Do you get any error in the console?
Is the
Cam Switch
button set in the Input Settings?Is the script attached to an active gameObject?
Is the condition evaluated to
true
(a simple Debug.Log above thecam1.enabled
will help)