private void Pickup() { if (curTarget != null) { holding = curTarget.Pecked(); holdingPeck = curTarget.GetThis(); if (holding != null) { holding.SetParent(transform); holding.localPosition = new Vector3(0, 0, 0.85f); } curTarget = null; } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { if (holdingPeck != null && PecksList._instance.peckables.ContainsKey(holdingPeck.ID())) { stream.SendNext(holdingPeck.ID()); } else { stream.SendNext(99999); } stream.SendNext(SendChirp); SendChirp = false; } else { int index = (int)stream.ReceiveNext(); bool alreadyHolding = false; // If holding something if (index != 99999) { IPeckable pecked = PecksList._instance.peckables[index]; if (holdingPeck == pecked) { alreadyHolding = true; // If already holding it } else { holdingPeck = pecked; // else } } // If not holding anything else { // If you are holding then drop it if (holding != null) { holdingPeck.Released(); holding.SetParent(null); holdingPeck = null; holding = null; } } // If you started holding something, run pickup code if (holdingPeck != null && alreadyHolding == false) { holding = holdingPeck.Pecked(); holding.SetParent(transform); holding.localPosition = new Vector3(0, 0, 0.85f); } if ((bool)stream.ReceiveNext()) { Chirp(); } } }