| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using UnityEngine;
- using System.Collections.Generic;
- public class House : MonoBehaviour
- {
- [SerializeField] private int maxResidents = 4;
- private List<Villager> residents = new List<Villager>();
- public bool HasSpace => residents.Count < maxResidents;
- public int ResidentCount => residents.Count;
- void Start()
- {
- Debug.Log("House created");
- }
- public bool AddResident(Villager villager)
- {
- if (HasSpace && !residents.Contains(villager))
- {
- residents.Add(villager);
- Debug.Log($"Villager {villager.villagerName} moved into house. Residents: {residents.Count}/{maxResidents}");
- return true;
- }
- return false;
- }
- public void RemoveResident(Villager villager)
- {
- if (residents.Contains(villager))
- {
- residents.Remove(villager);
- Debug.Log($"Villager {villager.villagerName} left house. Residents: {residents.Count}/{maxResidents}");
- }
- }
- public string GetBuildingInfo()
- {
- return $"House\nResidents: {residents.Count}/{maxResidents}";
- }
- void OnDrawGizmos()
- {
- // Show house occupancy
- Gizmos.color = HasSpace ? Color.green : Color.red;
- Gizmos.DrawWireCube(transform.position + Vector3.up * 1.5f, Vector3.one * 0.3f);
- }
- }
|