Example #1
0
    /* Performs an action based on the given target and the unit's type */
    public void startPerformingAction(GameObject entity)
    {
        //Attacks another unit
        if (entity.GetComponent <Unit>() != null)
        {
            AttackComponent attack = gameObject.GetComponent <AttackComponent>();
            if (attack != null)
            {
                Debug.Log("ATTACK");
                actionList.Clear();
                actionList.Add(attack.InstantiateAttackComponent(gameObject, entity));
            }
            //Add a new attack action
            // startAttacking(entity);
        }
        //Checks if the entity to perform an action on is a resource
        ResourceObject resourceObject = entity.GetComponentInParent <ResourceObject>();

        if (resourceObject != null)
        {
            HarvestComponent harvest = gameObject.GetComponent <HarvestComponent>();
            //If harvesting is posible, do it
            if (harvest != null)
            {
                //Harvest
                actionList.Clear();
                actionList.Add(harvest.InstantiateHarvestAction(gameObject, resourceObject.gameObject));
            }
            //Other units move there
            else
            {
                stopAndMoveTo(entity.transform.position);
            }
        }
    }
Example #2
0
    public Harvest(GameObject character, GameObject targetResource)
    {
        this.character = character;
        this.target    = targetResource;
        Unit unitComponent = character.GetComponent <Unit>();

        movementHandler = unitComponent.movementHandler;
        unit            = unitComponent.unitEntity;
        harvestSpeed    = unit.attackTime;
        //Sets harvest component info, so that
        //harvested resources are not lost if this action is dequeued
        harvestComponent = character.GetComponent <HarvestComponent>();
        harvestComponent.resourceType = target.GetComponent <ResourceObject>().getResourceType();
        harvestAmount = harvestComponent.harvestAmount;
    }