TagPlayer









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

Featured Snippets


File name: ClickDetector.cs Copy
7  void Update()
8     {
9         // if this player is not "it", the player can't tag anyone, so don't do anything on collision
10         if (PhotonNetwork.player.ID != GameLogic.playerWhoIsIt)
11         {
12             return;
13         }
14
15         if (Input.GetButton("Fire1"))
16         {
17             GameObject goPointedAt = RaycastObject(Input.mousePosition);
18
19             if (goPointedAt != null && goPointedAt != this.gameObject && goPointedAt.name.Equals("monsterprefab(Clone)", StringComparison.OrdinalIgnoreCase))
20             {
21                 PhotonView rootView = goPointedAt.transform.root.GetComponent();
22                 GameLogic.TagPlayer(rootView.owner.ID);
23             }
24         }
25  }
File name: GameLogic.cs Copy
27     public void OnPhotonPlayerConnected(PhotonPlayer player)
28     {
29         Debug.Log("OnPhotonPlayerConnected: " + player);
30
31         // when new players join, we send "who's it" to let them know
32         // only one player will do this: the "master"
33
34         if (PhotonNetwork.isMasterClient)
35         {
36             TagPlayer(playerWhoIsIt);
37         }
38     }
File name: GameLogic.cs Copy
40     public static void TagPlayer(int playerID)
41     {
42         Debug.Log("TagPlayer: " + playerID);
43         ScenePhotonView.RPC("TaggedPlayer", PhotonTargets.All, playerID);
44     }
File name: GameLogic.cs Copy
53     public void OnPhotonPlayerDisconnected(PhotonPlayer player)
54     {
55         Debug.Log("OnPhotonPlayerDisconnected: " + player);
56
57         if (PhotonNetwork.isMasterClient)
58         {
59             if (player.ID == playerWhoIsIt)
60             {
61                 // if the player who left was "it", the "master" is the new "it"
62                 TagPlayer(PhotonNetwork.player.ID);
63             }
64         }
65     }

TagPlayer 123 lượt xem

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