- Home /
Spawning problems with cameras
Hi,
I've got a problem with the multiplayer game a friend and I are developing. Up to now the game does
- Display a GUI
- Set up server or client
- Spawn a player for the server and each client
- On the server there are some scripts for the enemies (spawning, AI, movement, ...)
The game runs good as long as there's only one camera in the scene. At the moment we're using a camera above the Scene showing the players and their enemies. Instead we would like to have a third person camera for each player. The player objects are prefabs that are spawned by a script that listens to the events OnPlayerConnected and OnServerInitialized. If we add a camera to the prefab something really strange happens: The cameras are given to the wrong persons. I can see my friends character and he sees mine. Nevertheless the movement doesn't change. If I press the move key on my keyboard, my character moves but what my camera sees is send to his PC. The core part of the spawnscript looks like this
function OnServerInitialized(){ Spawnplayer(); }
function OnConnectedToServer(){ Spawnplayer(); }
function Spawnplayer(){
var myNewTrans : Transform = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
This script comes from the M2H Network Tutorial.
Answer by YeOldeSnake 1 · Dec 29, 2010 at 11:57 AM
use NetworkView.Owner and NetworkView.isMine to enable/disable cameras like
if(!NetworkView.isMine){
camera.enabled=false;
}