void OnPlayerJoined(string playerPrefix) { if (playerNum >= maxPlayers) { /* Just ignore */ return; } /* Regardless of who joined, do away with the initial camera */ initialCamera.enabled = false; /* Create this player's ship */ Transform shipTransform = CreateShip(); /* Create an icon for the ship */ CreateIcon(shipTransform); /* Create a camera for this player */ Vector3 cameraPosition = shipTransform.position - shipTransform.position.normalized * 20.0f; Transform cameraTransform = Instantiate(cameraPrefab, cameraPosition, shipTransform.rotation) as Transform; /* Initialize the camera to follow the player's ship */ CameraFollow follower = cameraTransform.GetComponent <CameraFollow>(); Ship ship = shipTransform.GetComponent <Ship>(); follower.ship = ship; follower.lookAt = shipTransform; follower.followPoint = shipTransform.Find("CameraTarget"); /* Add a HUD for this player */ HUD hud = Instantiate(HUDPrefab, Vector3.zero, Quaternion.identity) as HUD; hud.ship = ship; /* Position the camera and canvas correctly on-screen */ Camera camera = cameraTransform.GetComponent <Camera>(); splitHelper.addCamera(camera, hud); /* Only render the player's own reticles */ camera.cullingMask = camera.cullingMask | (1 << (28 + playerNum)); /* Initialize the PlayerInput and disable it until everyone's ready */ PlayerInput input = shipTransform.GetComponent <PlayerInput>(); input.SetPlayerPrefix(playerPrefix); input.enabled = false; inputs.Add(input); /* Initialize the sound controller */ PlayerSoundController soundController = shipTransform.GetComponent <PlayerSoundController>(); soundController.soundSystem = soundSystem; /* Initialize respawn handler */ ShipRespawnHandler respawnHandler = shipTransform.GetComponent <ShipRespawnHandler>(); respawnHandler.terrain = terrain; playerNum++; }