public bool CanBuild() { bool hasEnoughResources = false; List <ResourceAmount> resourceAmounts = new List <ResourceAmount>(); for (int i = 0; i < resourceCosts.Count; i++) { ResourceAmount currentAmount = Resource.Instance.GetResourceAmount(resourceCosts[i].resourceType); ResourceAmount cost = resourceCosts[i]; if (currentAmount.resourceAmount >= cost.resourceAmount) { resourceAmounts.Add(currentAmount); } } if (resourceAmounts.Count >= resourceCosts.Count) { hasEnoughResources = true; // resourceAmounts has the same order as resourceCosts for (int i = 0; i < resourceCosts.Count; i++) { resourceAmounts[i].resourceAmount -= resourceCosts[i].resourceAmount; } buildingState = BuildingState.Building; GameEvents.BuildingStarted(this); GameEvents.OnTimePassed += CheckBuildingTime; } return(hasEnoughResources); }