Pb with score between level

Options
Hi All,

I have a pb and i don't find the solution.

- I created a game with 2 players.
- At the end of the level i have a door, if 1 of the 2 player touch the door, the 2 players are changing level.

- If the owner of the room is touching the door, scores for the 2 players are ok
- if not the owner of the room is touching the door, he is keeping his score, but the owner score is alway to 0.

I try with : - PlayerPrefs
- an object keeping the score :
public class ScorePlayer : MonoBehaviour {
	static public int score;
	public GameObject obj; // obj -> my ScorePlayer object
	void Start()  {
		DontDestroyOnLoad(obj);
	}
	
	void Update () {
	}
}

Here is my code for leaving level :
void OnTriggerEnter2D(Collider2D coll) {
	
		if (coll.gameObject.tag == "DoorEx") {

			photonView = this.GetComponent<PhotonView> ();	
			if (PhotonNetwork.isMasterClient)
			{
				PlayerPrefs.SetInt ("Score", score);
				ScorePlayer.score=score;
			        photonView.RPC ("PlayerDoor1", PhotonTargets.All, 1);
					
			}
		}


my rpc
[RPC]
	void PlayerDoor1(int location) {
		doorsky1 = location;
	}

and in my update
		if ((PhotonNetwork.isMasterClient) && (doorsky1 == 1)) 

				{
			
						photonView.RPC ("PlayerDoor1", PhotonTargets.All, 0);
				                PhotonNetwork.LoadLevel ("dyna02");
	
				} 

if you have any clues ? because i don't find where is the pb ?

many thanks

Comments

  • skyrace
    Options
    I also try with
    PhotonNetwork.player.SetCustomProperties(new PhotonHashTable(){{"Score",score}});
    

    That's working but i have also the same bug in the same situation like if a new player is created.

    Here is my code for creating players :
    	public void OnJoinedRoom()
    	{
    		PhotonNetwork.Instantiate(playerPrefab.name, new Vector3(0f, 5f, 0f), Quaternion.identity,0);
    		if (PhotonNetwork.playerList.Length == 2)
    		{
    			playerWhoIsName = PhotonNetwork.player.name;
    			PhotonNetwork.room.open = false;
    			PhotonNetwork.room.visible = false;
    		}
    		
    		Debug.Log("playerWhoIsIt: " + playerWhoIsIt);
    
    		
    	}
    	void OnLevelWasLoaded(int level)
    	{
    		if (level == 3) {   // -> first level
    			Debug.Log ("PLAYERLIST :" + PhotonNetwork.playerList);
    			PhotonNetwork.player.SetCustomProperties(new PhotonHashTable(){{"Score",0}});
    	            }
    
    		if (level == 4) {
    						PhotonNetwork.Instantiate (playerPrefab.name, new Vector3 (0f, 5f, 0f), Quaternion.identity, 0);
    				}
    	}
    

    Please help me because my game is finished and working i just have this bug in the network version.

    Thanks

    Best regards
  • vadim
    Options
    Keeping player score in custom properties is good idea.
    But what you mean 'same bug' when using properties? After connecting to room and setting 'Score' to some value, this parameter will persist until client is in room and is available on any other client connected via CustomProperties player property. It's not related to objects instantiation.
  • skyrace
    Options
    Hi

    thanks for the answer, i made a test with "dontdestroyonload" on my spawn object (so i just instantiate it on join room), now it is ok, it is keeping score.

    How can i tell to my 2 spawn player on load level to execute a "void function" from another script ?

    I should use rpc function ?

    I know how to use RPC in the same script but not from one script to another.
  • vadim
    Options
    Do you have reference to another script? If so, you can just call RPC() for it directly as you can do for any other public method.