#How do I link image visibility to active camera?

1 messages · Page 1 of 1 (latest)

north scroll
#

Hi it's me again. So I'm trying to link images on the gui to the cameras, so that they'll appear when the corresponding camera is active. Image 1 is on screen when camera 1 is active and so on. I wrote this code:

void resetPreviews()
    {
        for (int i = currentCam; i == cameras.Length; i++)
        {
            cameraPreviews[currentCam].enabled = false;
            currentCam = i;
            Debug.Log(i);
        }
        currentCam = 0;
        cameras[currentCam].enabled = true;
        cameraPreviews[currentCam].enabled = true;
    }```
But I don't think it's running, even when I put it in the awake or start functions
upbeat fern
#

so you switch between multible cameras and only if one specific camera is active the ui should be visible?

north scroll
#

Yes.

upbeat fern
#

you could either make a array of gamobject lists to so you can enable the once you want and disable all the others
or you could make a component that listen to the camera change and make it visbale / invisable based on what camera allowd to be active on

#

the difference is just where you store the data

north scroll
#

I've made two arrays. One for the cameras and one for the images

#

The problem is how do I disable all of them at the start except one

upbeat fern
#

loop over them and check if the index is the one that should be active

#

if not disable

#

if yes enable

north scroll
#

Isn't that kind of what I did above

upbeat fern
#

that would mean the for each camera is only one image

north scroll
#

Yeah. Each camera has an image assigned to it.

upbeat fern
#

are you sure that the condition for the for loop is correct?

#

i == cameras.Length does not seem right

#

maybe you meant

        for (int i = 0; i < cameras.Length; i++)
north scroll
#

That's it

#

I always mistake the second part with the condition to end

#

So I put down when I want it to end

upbeat fern