Can't change the Unity UI dispaly from script

Hello,

So I am working on my final project and I need to change display when I clicked the button on the screen. But when I clicked it, it only displays “Display 1 No Cameras Rendering”. Actually I need to change main cameras display with other cameras but it’s not working. Code and screenshot of UI is down below so I hope you can help me about it. Thanks.

[154789-adsız.png|154789]

void Start()
{
    mainCam.gameObject.SetActive(true);
    panoramicCam.gameObject.SetActive(false);
    button.onClick.AddListener(changeCamera);
}

void changeCamera()
{
    if(mainCam.gameObject.activeInHierarchy)

    {
        tempDisp = mainCam.targetDisplay;
        mainCam.targetDisplay = panoramicCam.targetDisplay;
        panoramicCam.targetDisplay = tempDisp;
        button.GetComponent<Text>().text = "Ana Kamera";
        text.text = "Kuşbakışı Kamera";
    }

    else
    {
        tempDisp = panoramicCam.targetDisplay;
        panoramicCam.targetDisplay = mainCam.targetDisplay;
        mainCam.targetDisplay = tempDisp;
        button.GetComponent<Text>().text = "Kuşbakışı Kamera";
        text.text = "Ana Kamera";
    }
}

}

Correction: When I try to change their activity in if statements problem is still same.