Networking problems assigning the right cam and object

Wrong cams get enabled when the 2nd player enters the game. Can’t seem to find out what I’m doing wrong.

AvatarControl.js

Player.js

Game Demo

Please wait for moderation

Some parts of your code aren't well formated so i could look through everything but just a wild guess. Do you disable player 1's camera if player 2 spawns? If not you should do it. It's enough to disable the Camera Component and the Audio Listener Component of the Camera gameobject if you need the object for something else.

Thank you for your reply, I have updated my question with pastebin links. Also the code inside is updated, if you could take a look. Thanks. Edit: I have updated the game demo with the new code.

In your Player.js script you have this line playerCam.camera.enabled = true; which gets executed when networkView.isMine returns true and false. I don't know about your gameobject structure and also which camera playerCam is when networkView.isMine returns false but i think enabled should be false here.

The Network.Instantiate creates a game object named Player(Clone) with a child camera object named playerCam. That one has the component SmoothFollow targeting the parent Player(Clone). The player object has the script Player.js with playerCam to child object. And there is a seperate empty game object that holds the script AvatarControl.js with the player Prefab.

1 Answer

1

Btw. I personally use a seperate script attached to the player Camera which contains something like this:

function Start(){
	if(!transform.root.networkView.isMine){
		transform.gameObject.active = false;	
	}
}