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); } }
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); } }
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; }
// 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); } }