Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Camera Change

Discussion in 'Scripting' started by tricks21, Apr 5, 2008.

  1. tricks21

    tricks21

    Joined:
    Oct 29, 2007
    Posts:
    13
    Hi guys, i'm new to unity so this may be a really simple question but i don't know how to fix it. I'm trying to change between two cameras. I need to switch between the two when the first person controller hits a trigger. I've tried many different things but i can't get the the 2nd camera to work. Any advice would be very helpful.

    Thanks
     
  2. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    try this....

    Code (csharp):
    1.  
    2. var camera1 : GameObject;
    3. var camera2 : GameObject;
    4.  
    5. function Start () {
    6.    camera1.camera.enabled = true;
    7.    camera2.camera.enabled = false;
    8. }
    9.  
    10. function Update () {
    11.    if (Input.GetKeyDown ("2")){
    12.       camera1.camera.enabled = false;
    13.       camera2.camera.enabled = true;
    14.    }
    15.    if (Input.GetKeyDown ("1")){
    16.       camera1.camera.enabled = true;
    17.       camera2.camera.enabled = false;
    18.    }    
    19. }
    20.