- Home /
Network Camera, Player
How can I have a main scene spawn a car on another game scene with each player having own cars that can shoot. I got it so far that I can drive and shoot and a Main menu. Its just the spawning that is the tricky part. It has gone all messed up a few times cuz of multiple audio listeners and the cameras switching to the other players car..
I got a script for network rigidbodies and a connect/disconnect script and a Instantiate(spawn) script for spawning cars/players.
I'd like that each player would have a different id so that the camera would know to what car it should follow. or something like that.
Answer by Itinerant · Sep 13, 2012 at 05:04 PM
I was having a similar problem when I was trying to set up a Photon cloud game. My solution was to turn off the camera in the player prefab, then turn it back on when it was instantiated. This keeps it from linking the other players cameras. You can check out the steps I ended up using here:
http://answers.unity3d.com/questions/314232/activating-a-child-object-in-c.html
Now, the camera doesnt get like updated or something cuz its just a grey screen, but I can see in the scene view that the car is there Edit: It wont enable the camera, I have no idea why it wont work. I have tried with GetComponent but nothing and there should be an .enabled to the camera object but it gives an error
It should. Just write a .enabled = true for wherever your camera is, and you should be good. I haven't fiddled around with the js commands for this particular solution yet (since Photon mostly uses C#), but I don't think the results should be any different.
Hmm, Can't seem to get the camera Object itself, gonna c if I find a way.
Well, I'm not sure but now I have only one car and each one that joins after get the same camera and cannot control the car..
That's strange...can you post the code that you're using to instantiate players onto the network?
Answer by Meater6 · Sep 13, 2012 at 04:19 PM
Why not just have one of the scripts (or a new script) that is on a car have a variable called: playerNum, and just set it to an appropriate integer (player 1: 1, Player 2 : 2...), and make the camera find the right one.
Or an even better solution, include the camera in the car prefab so that it spawns with the right car from the start.
Hope this helps!
I have a camera in the prefab but the problem is that the clients cam changes to the servers camera.. And about the number, How do I set it if I connect to the server from another scene and the spawning should work multiple times with same player?