PunRespawn









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

Featured Snippets


File name: PickupItem.cs Copy
105     public void Drop()
106     {
107         if (this.PickupIsMine)
108         {
109             this.photonView.RPC("PunRespawn", PhotonTargets.AllViaServer);
110         }
111     }
File name: PickupItem.cs Copy
114     public void Drop(Vector3 newPosition)
115     {
116         if (this.PickupIsMine)
117         {
118             this.photonView.RPC("PunRespawn", PhotonTargets.AllViaServer, newPosition);
119         }
120     }
File name: PickupItem.cs Copy
171     internal void PickedUp(float timeUntilRespawn)
172     {
173         // this script simply disables the GO for a while until it respawns.
174         this.gameObject.SetActive(false);
175         PickupItem.DisabledPickupItems.Add(this);
176         this.TimeOfRespawn = 0;
177
178         if (timeUntilRespawn > 0)
179         {
180             this.TimeOfRespawn = PhotonNetwork.time + timeUntilRespawn;
181             Invoke("PunRespawn", timeUntilRespawn);
182         }
183     }
File name: PickupItem.cs Copy
187     internal void PunRespawn(Vector3 pos)
188     {
189         Debug.Log("PunRespawn with Position.");
190         this.PunRespawn();
191         this.gameObject.transform.position = pos;
192     }
File name: PickupItem.cs Copy
195     internal void PunRespawn()
196     {
197         #if DEBUG
198         // debugging: in some cases, the respawn is "late". it's unclear why! just be aware of this.
199         double timeDiffToRespawnTime = PhotonNetwork.time - this.TimeOfRespawn;
200         if (timeDiffToRespawnTime > 0.1f) Debug.LogWarning("Spawn time is wrong by: " + timeDiffToRespawnTime + " (this is not an error. you just need to be aware of this.)");
201         #endif
202
203
204         // if this is called from another thread, we might want to do this in OnEnable() instead of here (depends on Invoke's implementation)
205         PickupItem.DisabledPickupItems.Remove(this);
206         this.TimeOfRespawn = 0;
207         this.PickupIsMine = false;
208
209         if (this.gameObject != null)
210         {
211             this.gameObject.SetActive(true);
212         }
213     }

PunRespawn 110 lượt xem

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