So, I got everything working fine in an array, but since I can’t get the same camera twice, I tried to transform it into a list… But it is activating the object of the camera, and not the camera itself
{
public Camera[] camerasArray;
public List<GameObject> camerasList;
public void camMainMove()
{
camerasArray[0].enabled = true;
camerasArray[1].enabled = false;
camerasArray[2].enabled = false;
}
private void Start()
{
camMainMove();
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
Invoke("SpawnRandom", 2);
}
}
public void SpawnRandom()
{
var randomInt = Random.Range(0, camerasList.Count);
for (int i = 0; i < camerasList.Count; i++)
{
camerasList[i].active = (i == randomInt);
}
}
public void ButtonRemove()
{
Removing();
}
void Removing()
{
for (int i = 0; i < camerasList.Count; i++)
camerasList.RemoveAt(i);
}
}
