GetScore









How do I use Get Score
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PickupDemoGui.cs Copy
15     public void OnGUI()
16     {
17         if (!PhotonNetwork.inRoom)
18         {
19             return;
20         }
21
22
23         if (this.ShowScores)
24         {
25             GUILayout.Label("Your Score: " + PhotonNetwork.player.GetScore());
26         }
27
28
29         if (this.ShowDropButton)
30         {
31             foreach (PickupItem item in PickupItem.DisabledPickupItems)
32             {
33                 if (item.PickupIsMine && item.SecondsBeforeRespawn <= 0)
34                 {
35                     if (GUILayout.Button("Drop " + item.name))
36                     {
37                         item.Drop(); // drops the item at the place where it originates
38                     }
39
40                     GameObject playerCharGo = PhotonNetwork.player.TagObject as GameObject;
41                     if (playerCharGo != null && GUILayout.Button("Drop here " + item.name))
42                     {
43                         // drop the item at some other place. next to the user's character would be fine...
44                         Vector3 random = Random.insideUnitSphere;
45                         random.y = 0;
46                         random = random.normalized;
47                         Vector3 itempos = playerCharGo.transform.position + this.DropOffset * random;
48
49                         item.Drop(itempos);
50                     }
51                 }
52             }
53         }
54
55
56         if (this.ShowTeams)
57         {
58             foreach (var teamName in PunTeams.PlayersPerTeam.Keys)
59             {
60                 GUILayout.Label("Team: " + teamName.ToString());
61                 List teamPlayers = PunTeams.PlayersPerTeam[teamName];
62                 foreach (PhotonPlayer player in teamPlayers)
63                 {
64                     GUILayout.Label(" " + player.ToStringFull() + " Score: " + player.GetScore());
65                 }
66             }
67
68             if (GUILayout.Button("to red"))
69             {
70                 PhotonNetwork.player.SetTeam(PunTeams.Team.red);
71             }
72             if (GUILayout.Button("to blue"))
73             {
74                 PhotonNetwork.player.SetTeam(PunTeams.Team.blue);
75             }
76         }
77     }
File name: PunPlayerScores.cs Copy
23     public static void AddScore(this PhotonPlayer player, int scoreToAddToCurrent)
24     {
25         int current = player.GetScore();
26         current = current + scoreToAddToCurrent;
27
28         Hashtable score = new Hashtable(); // using PUN's implementation of Hashtable
29         score[PunPlayerScores.PlayerScoreProp] = current;
30
31         player.SetCustomProperties(score); // this locally sets the score and will sync it in-game asap.
32     }
File name: PunPlayerScores.cs Copy
34     public static int GetScore(this PhotonPlayer player)
35     {
36         object teamId;
37         if (player.customProperties.TryGetValue(PunPlayerScores.PlayerScoreProp, out teamId))
38         {
39             return (int)teamId;
40         }
41
42         return 0;
43     }

GetScore 173 lượt xem

Gõ tìm kiếm nhanh...