OnPickedUpCall
How do I use On Picked Up Call
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
144 | if (this.OnPickedUpCall != null) | 1 |
File name: PickupItem.cs
Copy
124 public void PunPickup(PhotonMessageInfo msgInfo)
125 {
126 // when this client's RPC gets executed, this client no longer waits for a sent pickup and can try again
127 if (msgInfo.sender.isLocal) this.SentPickup = false;
128
129
130 // In this solution, picked up items are disabled. They can't be picked up again this way, etc.
131 // You could check "active" first, if you're not interested in failed pickup-attempts.
132 if (!this.gameObject.GetActive())
133 {
134 // optional logging:
135 Debug.Log("Ignored PU RPC, cause item is inactive. " + this.gameObject + " SecondsBeforeRespawn: " + SecondsBeforeRespawn + " TimeOfRespawn: " + this.TimeOfRespawn + " respawn in future: " + (TimeOfRespawn > PhotonNetwork.time));
136 return; // makes this RPC being ignored
137 }
138
139
140 // if the RPC isn't ignored by now, this is a successful pickup. this might be "my" pickup and we should do a callback
141 this.PickupIsMine = msgInfo.sender.isLocal;
142
143 // call the method OnPickedUp(PickupItem item) if a GameObject was defined as callback target
144 if (this.OnPickedUpCall != null)
145 {
146 // you could also skip callbacks for items that are not picked up by this client by using: if (this.PickupIsMine)
147 this.OnPickedUpCall.SendMessage("OnPickedUp", this);
148 }
149
150
151 // setup a respawn (or none, if the item has to be dropped)
152 if (SecondsBeforeRespawn <= 0)
153 {
154 this.PickedUp(0.0f); // item doesn't auto-respawn. must be dropped
155 }
156 else
157 {
158 // how long it is until this item respanws, depends on the pickup time and the respawn time
159 double timeSinceRpcCall = (PhotonNetwork.time - msgInfo.timestamp);
160 double timeUntilRespawn = SecondsBeforeRespawn - timeSinceRpcCall;
161
162 //Debug.Log("msg timestamp: " + msgInfo.timestamp + " time until respawn: " + timeUntilRespawn);
163
164 if (timeUntilRespawn > 0)
165 {
166 this.PickedUp((float)timeUntilRespawn);
167 }
168 }
169 }
OnPickedUpCall 110 lượt xem
Gõ tìm kiếm nhanh...