Search Unity

2 Camera how?

Discussion in 'Scripting' started by MrAwesome, Sep 5, 2011.

  1. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    Yeah i have a mulitiplayer game

    And i have set player1 to have camera1
    and player2 to have camera2,

    But when i "Run" it , it only shows one of the camera, how to make it show 2 cameras?
     
  2. Afisicos

    Afisicos

    Joined:
    Nov 13, 2010
    Posts:
    326
    I don't know if is posible split the screen in 2 rectangles, one for each cam, but there are a posibility using render to texture.

    You have to make 2 textures and use one cam for each one.
    then, you have to show the 2 textures as a GUI for example.
     
  3. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    it most certainly is possible.

    Camera1. Rect(0, 0, 1, 0.5)
    Camera2. Rect(0, 0.5, 1, 0.5)

    It all has to do with the Normalized Viewport Area. The numbers are based off of Screen.width and Screen.height (by percentage of them)
     
  4. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
  5. MrAwesome

    MrAwesome

    Joined:
    Sep 1, 2011
    Posts:
    171
    // Change the width of the viewport each time space key is pressed
    function Update () {
    if (Input.GetButtonDown ("Jump")) {
    // choose the margin randomly
    var margin = Random.Range (0.0, 0.3);
    // setup the rectangle
    camera.rect = Rect (margin, 0, 1 - margin * 2, 1);
    }
    }


    So this is the code?

    But how do i get it to work