Want two cameras to display the scene differently

I am building a simple 2D split screen game. All of the players start at the same location, but look different. Right now, one player is in front of all of the other players.

I want the player that is in front of all of the other players to vary between cameras. I would like player 1’s camera to display player 1 on top, players 2’s camera to display player 2 on top, etc.

Is this possible?

There are a few ways to do this.

  1. Have a foreground and background player object for each player. Each pair of gameObject would both move and act the same way as a single player object. However each object has a z position so all foreground objects are on top of all background objects and all objects are on different layers (let’s call them fg1, bg1, etc). Then each camera would only show 1 foreground and 3 background layers, depending on the camera. For instance player 1’s camera would show fg1, bg2, bg3, and bg4 layers. Since the gameObjects in the foreground layer are in front of the gameObjects in the background layer this means player 1 would always be in front for player 1. Do the same for the other three players (except switch fg1 with bg1 and bg# with fg#).

  2. Use two cameras, a foreground and background camera for each player camera. Assign the foreground camera to draw after the background camera. Then put each player on a different layer. Have player 1’s background camera only draw the layers player2, player3, and player 4 and player 1’s foreground camera draw the layer player1. This will create the effect that player 1 is always on top of the other 3 players. Do the same for the other 3 players.

Search and you will find this is common:

http://forum.unity3d.com/threads/2-cameras-running-the-same-time.44911/

35932-layers.jpg