Working on building logic, Stone Worker job added in, spawn transform added and spawn amount fixed.
This commit is contained in:
@@ -33,6 +33,7 @@ public class Building : MonoBehaviour
|
||||
[SerializeField] private BuildingType buildingType;
|
||||
[SerializeField] private GameObject unbuiltModel, constructingModel, activeModel, destroyedModel;
|
||||
[SerializeField] private StorageConfig[] storageConfig = new StorageConfig[0];
|
||||
[SerializeField] private Transform spawnLocation;
|
||||
public Dictionary<Resource.ResourceType, int> resourcesToStore = new Dictionary<Resource.ResourceType, int>();
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
@@ -129,7 +130,10 @@ public class Building : MonoBehaviour
|
||||
buildingState = BuildingState.Active;
|
||||
SetBuildingModel(buildingState);
|
||||
if(buildingType == BuildingType.House)
|
||||
UnitManagement.Instance.CreateUnit("Citizen", storageConfig.Length, transform.position);
|
||||
foreach (StorageConfig config in storageConfig)
|
||||
{
|
||||
UnitManagement.Instance.CreateUnit("Citizen", config.capacity, spawnLocation.transform.position);
|
||||
}
|
||||
}
|
||||
public void DestroyBuilding()
|
||||
{
|
||||
|
||||
@@ -42,7 +42,10 @@ public class GameManager : MonoBehaviour
|
||||
population += amountToAdd;
|
||||
break;
|
||||
}
|
||||
statistics[resourceToAdd] += amountToAdd;
|
||||
UIController.Instance.UpdateStats();
|
||||
}
|
||||
|
||||
public float GetResource(Resource.ResourceType resourceToGet)
|
||||
{
|
||||
switch (resourceToGet)
|
||||
|
||||
@@ -5,7 +5,7 @@ using UnityEngine.UI;
|
||||
|
||||
public class NPC : MonoBehaviour
|
||||
{
|
||||
public enum Job { Builder, Farmer, Soldier, Forester, Merchant, Miner, Citizen }
|
||||
public enum Job { Builder, Farmer, Soldier, Forester, Merchant, Miner, StoneWorker, Citizen }
|
||||
public Job job = Job.Citizen;
|
||||
|
||||
// Added a simple state tracker to cleanly separate gathering and traveling
|
||||
@@ -20,7 +20,7 @@ public class NPC : MonoBehaviour
|
||||
[SerializeField] Animator animationController;
|
||||
[SerializeField] float movementSpeed, interactionRadius;
|
||||
[SerializeField] Image jobImg;
|
||||
[SerializeField] Sprite miner, forester, citizen, farmer, merchant, soldier, builder;
|
||||
[SerializeField] Sprite miner, forester, citizen, farmer, merchant, soldier, builder, stoneWorker;
|
||||
|
||||
private Resource currentTargetResource;
|
||||
private Building currentTargetBuilding; // Cache the TownHall so we don't search for it every frame
|
||||
@@ -160,11 +160,19 @@ public class NPC : MonoBehaviour
|
||||
animationController.SetFloat("MoveSpeed", 0f);
|
||||
transform.LookAt(currentTargetBuilding.transform.position);
|
||||
|
||||
// You can reuse your IsHarvesting animation boolean, or create an "IsBuilding" one in the Animator
|
||||
animationController.SetBool("IsHarvesting", true);
|
||||
|
||||
// Tell the building to progress its construction
|
||||
// Tell the building to progress its construction (transitions from Unbuilt to Constructing on first call)
|
||||
currentTargetBuilding.StartBuilding();
|
||||
|
||||
// Play animation while building is constructing
|
||||
if (currentTargetBuilding.GetBuildingState() == Building.BuildingState.Constructing)
|
||||
{
|
||||
animationController.SetBool("IsHarvesting", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Stop animation when building is complete
|
||||
animationController.SetBool("IsHarvesting", false);
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveToLocation(Vector3 destination)
|
||||
@@ -293,10 +301,15 @@ public class NPC : MonoBehaviour
|
||||
CancelTask();
|
||||
break;
|
||||
case Job.Miner:
|
||||
resourceToWorkWith = Resource.ResourceType.Stone;
|
||||
resourceToWorkWith = Resource.ResourceType.Metal;
|
||||
jobImg.sprite = miner;
|
||||
CancelTask();
|
||||
break;
|
||||
case Job.StoneWorker:
|
||||
resourceToWorkWith = Resource.ResourceType.Stone;
|
||||
jobImg.sprite = stoneWorker;
|
||||
CancelTask();
|
||||
break;
|
||||
case Job.Citizen:
|
||||
resourceToWorkWith = Resource.ResourceType.Population;
|
||||
jobImg.sprite = citizen;
|
||||
|
||||
Reference in New Issue
Block a user