how do I switch between two Camera2D's

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mahmoud_Official

I used this code to switch the camera, but it only switches to camera 1 when I try to switch to camera 2 it stays on 1, help please.

 func _input(event):
  if Input.is_action_pressed("switch_players"):
    if camera2.is_current():
		camera1.clear_current()
		camera2.make_current()
	
	if camera1.is_current():
		camera2.clear_current()
		camera1.make_current()
:bust_in_silhouette: Reply From: Surtarso

just enable the camera with .current = true

there can only be one active camera, so whichever you set active to true will become the one

option1: camera 2 becomes enabled
if camera1.current = true: camera2.current = true
option2: camera 1 becomes enabled
if camera2.current = true: camera1.current = true

you dont even need the if statement really, just setting one to current will disable the other

Surtarso | 2021-02-16 16:43

thanks!!! I used this it worked!

    if camera1.current == true :
		camera2.current = true
	
	elif camera2.current == true :
		camera1.current = true

Mahmoud_Official | 2021-02-17 06:29