Search Unity

Multiple cameras switching and Camera Zoom-in Zoom-out

Discussion in 'Scripting' started by ashwan, Mar 5, 2010.

  1. ashwan

    ashwan

    Joined:
    Mar 3, 2010
    Posts:
    21
    Hello all,
    I am currently working on a project where i have to use multiple cameras for multiple players and also have to zoom in and zoom out the camera attached to that particular player when a action is performed.It would be a great help for me if you could suggest any method to perform this functions through scripting. Any links related to this will also be very much useful to me.
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Switching cameras is just a matter of using the enabled property to disable the current camera as you enable the one you want to switch to. Zooming in and out can be done simply by moving the camera nearer to the subject or else by changing the fieldOfView property.
     
  3. nairb

    nairb

    Joined:
    Mar 5, 2010
    Posts:
    2
    Andeee is correct. You could assign a key for you to interchange the cameras you are using. For a simple 2-camera script, you can do something like the code below:

    Camera camera1;
    Camera camera2;

    ...

    if ( Input.GetKeyDown(KeyCode.C) camera2 )
    {
    camera1.enabled = true;
    camera2.enabled = false;
    }
    else {
    camera2.enabled = false;
    camera1.enabled = true;
    }


    For multiple cameras, you need a little bit more complex script than above. For the zoom in/zoom out, you could tweak either the fieldOfView (which might distort the view a little bit) or the actual position of the camera, bringing it closer to your target.

    Cheers,
    Nairb