Hi Lumos
While you wait for Aren to answer I tell you what I do. This may help you with keeping track of scores by storing the score of every player in the player class and broadcasting it to all players.
In the game i have i need to get two players to compete against each other and i therefore need to:
1) Know the score of the other player
2) Know the nickname set by the other player
3) Know the position, the name and other parameters of the other player
I solve 1 and 2 by adding the values into the class responsible for the player which I can NDPlayer.
I find my object by calling NDPlayer.instance and I set properties that I can synch over the network (set;get) with and RFC
Example of score:
private string NeonDanceScoreBackProp;
public string NeonDanceScore{
set{
tno.Send("OnNeonDanceScore", TNet.Target.OthersSaved, value);
}
get{
return this.NeonDanceScoreBackProp;
}
}
[RFC]
void OnNeonDanceScore(string score){
NeonDanceScoreBackProp = score;
}
You can do the same for his nickname and anything else. You can store there his TNet ID if you want.
So by calling "NDPlayer.instance.NeonDanceScore" I set the score of my player (copy the score into this class value when you call to update the score) and deliver it to all other players.
Now. The problem is to find the other player so that I can read the values that he is setting into his NDPlayer.
I do this. I set a gameObject that I call Player2 as global var - this will be the opponent. And i load Player2 like this:
NDPlayer
[] ndPs
= FindObjectsOfType
(typeof(NDPlayer
)) as NDPlayer
[]; Debug.Log ("Total Players NDPlayers: "+ndPs.Length);
foreach (NDPlayer pl in ndPs) {
Debug.Log ("P2 is "+pl.gameObject.name);
Debug.Log ("Is this mine? "+pl.IsMine());
// assign P2 as the one that is not mine - created by me
if(!pl.IsMine())
Player2 = pl.gameObject;
}
I look for all objects of type NDPlayer and I load with Player2 the one that is not mine. Clearly.
To determine if is mine, in the NDPlayer class in Awake() I load the property IsMine like this
void Awake () {
isMine = TNManager.isThisMyObject;
}
Then i have a method that i can call on the instance to know if that gameObject was created by me:
/// <summary>
/// Determines whether this instance is this mine.
/// </summary>
/// <returns><c>true</c> if this instance is this mine; otherwise, <c>false</c>.</returns>
public bool IsMine(){
return isMine;
}
So once you find the Player2 you have all the other information about the player (my point 3 above) like rotation, position etc. and you can show the correct information to both players.
As long as you have two players only in the contest you can make all the decision by using the TNManager.isHosting. if you have more players you have to make a different design.
Hope this helps a little.
Cheers
Egi