Working on building logic, Stone Worker job added in, spawn transform added and spawn amount fixed.

This commit is contained in:
2026-06-12 16:30:41 +01:00
parent d99b2197e5
commit 10d6c0fa34
11 changed files with 1663 additions and 10 deletions

View File

@@ -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;