Search Unity

(SOLVED) Activating a camera (in a list)

Discussion in 'Scripting' started by MoreThanWinner, Sep 3, 2018.

  1. MoreThanWinner

    MoreThanWinner

    Joined:
    Jul 27, 2018
    Posts:
    19
    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
    Code (CSharp):
    1. {
    2.  
    3.     public Camera[] camerasArray;
    4.     public List<GameObject> camerasList;
    5.  
    6.  
    7.     public void camMainMove()
    8.     {
    9.         camerasArray[0].enabled = true;
    10.         camerasArray[1].enabled = false;
    11.         camerasArray[2].enabled = false;
    12.     }
    13.     private void Start()
    14.     {
    15.         camMainMove();
    16.     }
    17.     void OnTriggerEnter2D(Collider2D collision)
    18.     {
    19.         if (collision.CompareTag("Player"))
    20.         {
    21.             Invoke("SpawnRandom", 2);
    22.  
    23.  
    24.         }
    25.     }
    26.  
    27.  
    28.    
    29.     public void SpawnRandom()
    30.     {
    31.         var randomInt = Random.Range(0, camerasList.Count);
    32.  
    33.         for (int i = 0; i < camerasList.Count; i++)
    34.         {
    35.             camerasList[i].active = (i == randomInt);
    36.  
    37.         }
    38.  
    39.     }
    40.  
    41.     public void ButtonRemove()
    42.     {
    43.         Removing();
    44.        
    45.     }
    46.  
    47.     void Removing()
    48.     {
    49.         for (int i = 0; i < camerasList.Count; i++)
    50.             camerasList.RemoveAt(i);
    51.  
    52.     }
    53.  
    54.  
    55. }
    upload_2018-9-3_17-17-41.png
     
  2. lipisis

    lipisis

    Joined:
    Jan 14, 2017
    Posts:
    37
  3. MoreThanWinner

    MoreThanWinner

    Joined:
    Jul 27, 2018
    Posts:
    19
    No, I already tried it and nothing changed.
    What I need is a way to activate both the object of the camera and the component "camera". Plus I need to do it in a list so the "(your gameobject).camera.enabled = true;" won't work
     
    Last edited: Sep 3, 2018