Hi, now I have an additional problem. I would like to set up a player prefab with an animated playermesh and a weaponmesh. The prefab contains a camera that should render only the weapon but not the player's body. Now let's look what happens if someone plays the game:
Can I change the layer of a GameObject during runtime ? If this is possible I could make a check for networkView.isMine and change the layer individually on each machine.
Is there something like camera.Ignore(GameObject) ? If there's something like this, how can I still render the children of the ignored GameObject ?
You can most definitely change the layer during runtime... From the scripting reference:
If you want to continue with your way, you can setup the layers (for example) as
MyWeapon, MyPlayer, OtherWeapons, OtherPlayers.
Then, you can use Camera.cullingMask on your camera to decide what it renders, and what not. You can either edit your prefab of the player (change the camera's cullingMask in the inspector) Or you can have a variable in your spawn script:
If it's public you can edit it in the inspector, just like you edit the cullingMask.
When you instantiate your local player, just assign:
When you instantiate a remote player, move the relevant game objects on the instantiated player to the appropriate layers (OtherPlayers, OtherWeapons). The camera will do the rest.
Alternatively, you can also create two prefabs - one for a local player, one for a remote one.
BTW, just out of curiosity - why would you not want to display other player's weapons? (Unless the weapon is a heavy object and you want to replace it with some low poly object)
answered May 08 '11 at 02:14 PM