예제 #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);
            }
        }
    }