How can i switch between multiple cameras using one key click ?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SwitchCameras : MonoBehaviour {

    public Camera mainCamera;
    public Camera spaceShipCamera;
    public Camera teleportationCamera;

    private void Start()
    {
        mainCamera.enabled = true;
        spaceShipCamera.enabled = false;
        teleportationCamera.enabled = false;
    }

    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            //Swap enabled state to opposite one provided that only is on at a time
            mainCamera.enabled = !mainCamera.enabled;
            spaceShipCamera.enabled = !spaceShipCamera.enabled;
            teleportationCamera.enabled = !teleportationCamera.enabled;
        }
    }
}

This is switching only between two cameras.
I want it to switch between the three cameras each time i click on C then switch to spaceShipCamera then to teleportationCamera and then again back to the mainCamera. And in the future if i will have more cameras so switch between them too.

Have array of cameras, then switch current camera from that, like:
https://github.com/UnityCommunity/UnityLibrary/blob/master/Scripts/Camera/CameraSwitcher.cs

1 Like

Thanks working perfect.