House.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public class House : MonoBehaviour
  4. {
  5. [SerializeField] private int maxResidents = 4;
  6. private List<Villager> residents = new List<Villager>();
  7. public bool HasSpace => residents.Count < maxResidents;
  8. public int ResidentCount => residents.Count;
  9. void Start()
  10. {
  11. Debug.Log("House created");
  12. }
  13. public bool AddResident(Villager villager)
  14. {
  15. if (HasSpace && !residents.Contains(villager))
  16. {
  17. residents.Add(villager);
  18. Debug.Log($"Villager {villager.villagerName} moved into house. Residents: {residents.Count}/{maxResidents}");
  19. return true;
  20. }
  21. return false;
  22. }
  23. public void RemoveResident(Villager villager)
  24. {
  25. if (residents.Contains(villager))
  26. {
  27. residents.Remove(villager);
  28. Debug.Log($"Villager {villager.villagerName} left house. Residents: {residents.Count}/{maxResidents}");
  29. }
  30. }
  31. public string GetBuildingInfo()
  32. {
  33. return $"House\nResidents: {residents.Count}/{maxResidents}";
  34. }
  35. void OnDrawGizmos()
  36. {
  37. // Show house occupancy
  38. Gizmos.color = HasSpace ? Color.green : Color.red;
  39. Gizmos.DrawWireCube(transform.position + Vector3.up * 1.5f, Vector3.one * 0.3f);
  40. }
  41. }