Exemplo n.º 1
0
    public virtual void CollectPickup(PlayerControl player)
    {
        // does player already own me?
        if (player.Pickups.Contains(this))
        {
            // just update my state
            this.Player = player;
            gameObject.SetOwner(player.gameObject);
            transform.SetParent(player.transform);
            transform.localPosition = Vector3.zero;
        }
        else
        {
            // Show pickup message
            if (GameBrain.Instance.State == PlayState.GameOn && PlayerHudCanvas.Instance != null)
                    PlayerHudCanvas.Instance.ShowPickupText(this.GetPickupName(), player.gameObject, player.PlayerIndex);

            // check if player already has one of these
            var duplicate = player.Pickups.Find(x => x.GetPickupName() == this.GetPickupName() && x != this);
            if (duplicate != null)
            {
                // already got one, take ammo etc and destroy
                var ammo = GetAmmoCount();
                if (ammo > 0)
                {
                    duplicate.AddAmmo(ammo);
                }
                Destroy(gameObject);
            }
            else
            {
                // pick it up
                this.Player = player;
                player.AddPickup(this);

                gameObject.SetOwner(player.gameObject);
                transform.SetParent(player.transform);
                transform.localPosition = Vector3.zero;

                OnPlayerPickup.Invoke();
            }

            // play pickup sound
            if (PickupSound != null)
                Helper.PlaySoundEffect(PickupSound);
        }
    }