private IEnumerator actionGetResourcesCoroutine(SResources sresources) { int i = 0; while (Utilities.navMeshHaveReachDestination(m_agent) == false) { if (i * 0.5f > m_timeMaxToReachDest) { Debug.LogWarning("The agent " + ID + " didn't suceed to reach his destination"); yield break; } yield return(new WaitForSeconds(0.5f)); i++; } print("nav mesh true"); //add resources until the resources is empty. while (sresources.Contains != new Resources()) { print("try to get resources with " + ID); yield return(new WaitForSeconds(m_speedHarvest)); Resources resources = sresources.getResources(Constant.RESOURCESTOGET, m_belongsTo); } }
public List <SResources> getSResourcesNearBy(float radius, SResources addNotThisOne = null) { int layerMask = ~(LayerMask.GetMask("Floor") | LayerMask.GetMask("Selectable")); var hitColliders = Physics.OverlapSphere(transform.position, radius, layerMask); List <SResources> resources = new List <SResources>(); if (hitColliders.Length > 0) { foreach (Collider collider in hitColliders) { if (collider.TryGetComponent(out SResources sresources)) { if (sresources != addNotThisOne) { resources.Add(sresources); } } } } nearerToFirstOne(resources); return(resources); }
public void harvest(RaycastHit rayHit) { if (rayHit.collider.gameObject.layer == LayerMask.NameToLayer("Selectable")) { SObject sobject = SObject.getSobjectFromSelectionField(rayHit.collider.gameObject); if (sobject is SResources) { print("gonna to harvest " + ID); SResources sresources = (SResources)sobject; actionGetResources(sresources); if (m_belongsToSquad != null) { m_belongsToSquad.harvestSquad(sresources); } } } }
public override void onClick(SObject sobject) { base.onClick(sobject); print("on click sobject"); //if the builder was building a construction, we reduce the number of builder on this construction if (m_buildingUnderConstruction != null) { m_buildingUnderConstruction.BuilderOnConstruction--; m_buildingUnderConstruction = null; } if (sobject is SResources) { print("gonna to harvest " + ID); SResources sresources = (SResources)sobject; actionGetResources(sresources); if (m_belongsToSquad != null) { m_belongsToSquad.harvestSquad(sresources); } print("get resources"); } if (sobject is SBuilding) { SBuilding sbuilding = (SBuilding)sobject; if (sbuilding.BelongsTo != m_belongsTo) { print("gonna to attack " + ID); //TODO add attack here } else { //if the building is in construction we continue the construction if (sbuilding.IsInConstruction) { continueConstructBuilding(sbuilding.gameObject); } } } }
public void actionGetResources(SResources sresources) { StartCoroutine(actionGetResourcesCoroutine(sresources)); }