Ejemplo n.º 1
0
    void TryToUseObject(GameObject animal)
    {
        if (ObjectInHand != null)
        {
            AnimalStatistics stats = animal.GetComponent <AnimalStatistics>();
            HeldObject       obj   = ObjectInHand.GetComponent <HeldObject>();

            if (!obj.IsCarryingUnits())
            {
                return;
            }

            float food  = 0;
            float water = 0;
            switch (obj.GetTypeOfObject())
            {
            case TypeOfObject.ResourceCollector:
                stats.RetrieveResourceFromAnimal();
                break;

            case TypeOfObject.Bucket:
                water = (obj.IsCarryingUnits() ? obj.GetNumUnitsHeld() : 0);
                ConsumedPerpetualObject();
                break;

            case TypeOfObject.Hay:
                food = obj.GetNumUnitsHeld();
                ConsumedOneTimeUseObject();
                break;
            }
            stats.GiveFoodAndWater(food, water);
        }
    }
Ejemplo n.º 2
0
    void CollectResource(GameObject obj)
    {
        ResourceSource source = obj.GetComponent <ResourceSource>();

        switch (CurrentState)
        {
        case PlayerState.EmptyHand:
            if (source.GetTypeOfSource() == TypeOfSource.Feed)
            {
                GameObject held = source.GetHeldObject();
                if (held == null)
                {
                    break;
                }

                held.GetComponent <HeldObject>().SetNumUnitsHeld(source.UnitsTakenFromSource());
                PickupObject(held);
            }
            break;

        case PlayerState.HoldingObject:
            if (source.GetTypeOfSource() == TypeOfSource.Water)
            {
                HeldObject held = ObjectInHand.GetComponent <HeldObject>();
                if (held.GetTypeOfObject() != TypeOfObject.Bucket || held.IsCarryingUnits())
                {
                    break;
                }
                held.SetNumUnitsHeld(source.UnitsTakenFromSource());
                held.ChangeObjectState();
                FindObjectOfType <AudioManager>().Play("wellSFX");
            }
            break;
        }
    }