Exemplo n.º 1
0
    private void AnimateItemPickup()
    {
        GameObject item;

        switch (_type)
        {
        case Pickup.Health:
            item = _healthPickup;
            break;

        case Pickup.Power:
            item = _powerPickup;
            break;

        case Pickup.Fov:
            item = _fovPickup;
            break;

        default:
            throw new ArgumentOutOfRangeException("_type");
        }

        item.SetActive(true);
        item.transform.SetParent(null, true);
        item.transform.position = (Vector2)Position;

        var sequence = DOTween.Sequence();

        sequence.Append(item.transform.DOScale(1.0f, 0.5f).SetRelative().SetEase(Ease.OutElastic));
        sequence.AppendInterval(0.5f);
        sequence.OnComplete(
            () =>
        {
            if (_type == Pickup.Power)
            {
                _inventoryController.AddPower();
            }
            else if (_type == Pickup.Health)
            {
                _inventoryController.AddHealth();
            }
            else if (_type == Pickup.Fov)
            {
                _inventoryController.AddFov();
            }

            Destroy(item);
        });
    }