Пример #1
0
    private IEnumerator GatherResources(ResourceSource source)
    {
        source.StartGathering();
        while (source.resourceAmount > 0 && this.currentResourceAmount < this.m_ResourceCarryCapacity)
        {
            this.currentResourceAmount += source.GatherResource(m_GatherSpeed, this.m_ResourceCarryCapacity - this.currentResourceAmount);
            if (source.resourceAmount > 0)
            {
                yield return(new WaitForSeconds(1));
            }
        }
        source.StopGathering();

        lockedTrees.Remove(source.transform);

        if (this.currentResourceAmount == this.m_ResourceCarryCapacity)
        {
            SetNewState(State.GotoWoodBuilding);
            StartCoroutine(GotoWoodBuilding(this.m_ClosestWoodBuilding));
        }
        else
        {
            SetNewState(State.LookingForTarget);
        }
    }
Пример #2
0
 void GatherUpdate()
 {
     if (curResourceSource == null)
     {
         SetState(UnitState.Idle);
         return;
     }
     LookAt(curResourceSource.transform.position);
     if (Time.time - lastGatherTime > gatherRate)
     {
         lastGatherTime = Time.time;
         curResourceSource.GatherResource(gatherAmount, player);
     }
 }
Пример #3
0
    private IEnumerator GatherResources(ResourceSource source)
    {
        source.StartGathering();
        while (source.resourceAmount > 0)
        {
            WoodResource += source.GatherResource(gatherSpeed, m_MaxGatherCapacity - WoodResource);
            if (source.resourceAmount > 0)
            {
                yield return(new WaitForSeconds(1));
            }
        }
        source.StopGathering();

        IsGathering        = false;
        CanGatherResources = false;
    }
Пример #4
0
    // called every frame the 'Gather' state is active
    void GatherUpdate()
    {
        // if the resource is gone, go idle
        if (curResourceSource == null)
        {
            SetState(UnitState.Idle);
            return;
        }

        // look at the resource
        LookAt(curResourceSource.transform.position);

        // gather the resource every 'gatherRate' seconds
        if (Time.time - lastGatherTime > gatherRate)
        {
            lastGatherTime = Time.time;
            curResourceSource.GatherResource(gatherAmount, player);
        }
    }