I have set up a player spawner and put it in an empty game object
var players:NetworkPlayer[];
var player1Prefab:GameObject;
var player2Prefab:GameObject;
var player1SpawnPos:GameObject;
var player2SpawnPos:GameObject;
var spawnedObject:GameObject;
//var spawnSheet:GameObject;
var musicGameObject:GameObject;
var GUITextObject:GameObject;
var GUIExcellentObject:GameObject;
function Awake(){
Debug.Log("loaded level");
if(Network.isServer){
Debug.Log("network is server");
spawnedObject=Network.Instantiate(player1Prefab,player1SpawnPos.transform.position,player1SpawnPos.transform.rotation,0);
Debug.Log("i spwned you");
spawnedObject.GetComponent("DetectionScript").spawnSheet=player1SpawnPos.transform.position;
Debug.Log("assigned Spawn Sheet");
spawnedObject.GetComponent("DetectionScript").musicGameObject=musicGameObject;
Debug.Log("Assigned music game object");
spawnedObject.GetComponent("StageCompletedScript").GUITextObject=GUITextObject;
Debug.Log("assigned text object");
spawnedObject.GetComponent("StageCompletedScript").GUIExcellentObject=GUIExcellentObject;
Debug.Log("assigned gui excellent object");
spawnedObject.GetComponent("StageCompletedScript").musicGameObject=musicGameObject;
Debug.Log("assigned music game object");
}
else if(Network.isClient){
Debug.Log("network is client");
spawnedObject=Network.Instantiate(player2Prefab,player2SpawnPos.transform.position,player2SpawnPos.transform.rotation,0);
Debug.Log("i spwned you");
spawnedObject.GetComponent("DetectionScript").spawnSheet=player2SpawnPos.transform.position;
spawnedObject.GetComponent("DetectionScript").musicGameObject=musicGameObject;
spawnedObject.GetComponent("StageCompletedScript").GUITextObject=GUITextObject;
spawnedObject.GetComponent("StageCompletedScript").GUIExcellentObject=GUIExcellentObject;
spawnedObject.GetComponent("StageCompletedScript").musicGameObject=musicGameObject;
}
}
function OnPlayerDisconnected(player: NetworkPlayer) {
Debug.Log("Clean up after player " + player);
Network.RemoveRPCs(player);
Network.DestroyPlayerObjects(player);
}
I have also set up a component that disables behaviours if youre not the owner of the networkview , and added it to each player prefab.
var assignedCamera:GameObject;
var intendedPlayer:int;
var players:NetworkPlayer[];
var audioListener:Behaviour;
var tpsWalker:Behaviour;
var mouseLook:Behaviour;
var detectionScript:Behaviour;
var objectiveSystem:Behaviour;
var stageCompletedScript:Behaviour;
var zoomScript:Behaviour;
var changeRenderingPath:Behaviour;
var ingameMenu:Behaviour;
var smoothFollow:Behaviour;
var playerAudioManager:Behaviour;
var firstPersonToggleScript:Behaviour;
function OnNetworkInstantiate () {
//if(NetworkPlayer==players[intendedPlayer]){
if(!networkView.isMine){
assignedCamera.camera.enabled=false;
audioListener.enabled=false;
tpsWalker.enabled=false;
mouseLook.enabled=false;
detectionScript.enabled=false;
objectiveSystem.enabled=false;
stageCompletedScript.enabled=false;
zoomScript.enabled=false;
changeRenderingPath.enabled=false;
ingameMenu.enabled=false;
}
}
Ive set up the intended player variable in different prefabs i spawn. Note that this is a 2 player coop so generic code for a lot of waypoints and spawning is not needed.
Now on to the problems:
- *SOLVED*The first script spawns the players but its spawning is done in a way where both players have control over both the character controllers but sending position to the other player is only done in the character controller intended so if you move, both will move but the other player will only see YOU move and not himself so there might be a problem with the second script as well.SOLVED
- The first script fails to assign the values i want correctly and hands me this error
InvalidCastException: Cannot cast from source type to destination type. (wrapper dynamic-method) NetworkedDetectionScript.NetworkedDetectionScript$spawnSheet= (object,object[]) Boo.Lang.Runtime.RuntimeServices.Dispatch (object,string,System.Type[],object[],Boo.Lang.Runtime.DynamicDispatching.DispatcherCache/DispatcherFactory)
Boo.Lang.Runtime.RuntimeServices.Dispatch
(object,string,object,Boo.Lang.Runtime.DynamicDispatching.DispatcherCache/DispatcherFactory)
Boo.Lang.Runtime.RuntimeServices.SetProperty
(object,string,object)
SpawnManager.Awake () (at Assets/AAA STOOF/Networking
Assets/SpawnManager.js:18)
What could i be doing wrong
EDIT: I added onnetworkinstantiate() instead of awake and problem 1 is solved , now on to problem 2