SetTeam
How do I use Set Team
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: OnCollideSwitchTeam.cs
Copy
9 public void OnTriggerEnter(Collider other)
10 {
11 // it's ridiculously easy to switch teams. you only have to make sure you do it for your own characters
12 // (this trigger is called on all clients, when a user's character enters the trigger...)
13
14 // find a PhotonView and check if the character "isMine". Only then, set this client's player-team.
15 PhotonView otherPv = other.GetComponent
16 if (otherPv != null && otherPv.isMine)
17 {
18 PhotonNetwork.player.SetTeam(this.TeamToSwitchTo);
19 }
20 }
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
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: PunTeams.cs
Copy
96 public static void SetTeam(this PhotonPlayer player, PunTeams.Team team)
97 {
98 if (!PhotonNetwork.connectedAndReady)
99 {
100 Debug.LogWarning("JoinTeam was called in state: " + PhotonNetwork.connectionStateDetailed + ". Not connectedAndReady.");
101 }
102
103 PunTeams.Team currentTeam = PhotonNetwork.player.GetTeam();
104 if (currentTeam != team)
105 {
106 PhotonNetwork.player.SetCustomProperties(new Hashtable() {{PunTeams.TeamPlayerProp, (byte) team}});
107 }
108 }
SetTeam 131 lượt xem
Gõ tìm kiếm nhanh...