Is there a way to assign a int number to a gameobject array?

I want to assign an int to an array of gameobjects like the title says.

It should look something like this:

int currentCamera;

currentCamera = cameras[]

I want that, because if I run a void I want to check if a specific camera is active, like that:

if(currentCamera == 5)

and then do something.

I could do it with a lot of bools, but this would be so messy that it’s way smarter to do it like this.

Thanks in advance Max.

That’s not a thing.

Check some tutorials or examples on arrays and how to access elements within them.

Accessing elements of an array can be called:

  • accessing elements of array
  • indexing the array
  • dereferencing
  • looking up

Wrap your relevant data in a class or struct:

public class ActiveCamera
{
  public Camera camera;
  public bool isActive;
}

Then create an array of that wrapper:

ActiveCamera[] cams = //etc...

Then filter the array to get the relevant object you’re looking for:

Camera current = GetCurrentCamera();

//...

Camera GetCurrentCamera()
{
  Camera current = null;

  for(int i = 0; i < cams.Length; i++)
  {
    if(cams[i].isActive)
    {
      current = cams[i].camera;
      break;
    }
  }

  return current;
}