/// <summary> /// Initialize the Villager with the ability to move to given targets and the villagerAI. /// Set his state to THINKING for further decision making. /// </summary> void Start() { villagerName = RandomVillagerNamer.GetRandomName(); villagerAI = GetComponent <VillagerAI>(); villagerMovement = GetComponent <VillagerMovement>(); villagerState = VillagerState.THINKING; }
//private NavMeshAgent agent; private void Awake() { health = GetComponent <Health>(); health.Healed += Health_Healed; npchealth = GetComponent <NPCHealth>(); npchealth.Died += NPCHealth_Died; compVillagerMovement = GetComponent <VillagerMovement>(); ts = GetComponent <TimeScale>(); //agent = GetComponent<NavMeshAgent>(); }
void OnTriggerStay2D(Collider2D other) { if (other.gameObject.name == "Player") { if (Input.GetKeyUp(KeyCode.Space)) { if (!dialogueManager.dialogueActive) { dialogueManager.dialogueLines = dialogueLines; dialogueManager.currentLine = 0; dialogueManager.ShowDialogue(); } VillagerMovement villager = GetComponentInParent <VillagerMovement>(); if (villager != null) { dialogueManager.dialogueActive = true; villager.canMove = false; } } } }
void Start() { move = gameObject.GetComponent <VillagerMovement>(); diag = gameObject.GetComponent <DialogueTrigger>(); spr = gameObject.GetComponent <SpriteRenderer>(); if (move != null) { canMove = true; if (move.enabled == true) { notMoving = false; } else { notMoving = true; if (facingRight) { sprFacingRight = spr.flipX; } else { sprFacingRight = !(spr.flipX); } } } else { canMove = false; if (facingRight) { sprFacingRight = spr.flipX; } else { sprFacingRight = !(spr.flipX); } } }
private void Start() { List <Transform> housePositions = kp.GetKeyPoints(); #if PRINT_HOUSE_COUNT Debug.Log("Number of houses: " + housePositions.Count); #endif // All of the villagers are spawned here. // Loop for each transform. foreach (Transform trans in housePositions) { // Instantiate a new villager. GameObject newVillager = Instantiate(villagerPrefab, trans.position, Quaternion.identity); // Get the villager's relevant components for assignment operations. VillagerMovement vm = newVillager.GetComponent <VillagerMovement>(); VillagerStatus vs = newVillager.GetComponent <VillagerStatus>(); TimeControllable tc = newVillager.GetComponent <TimeControllable>(); // Assign the house to the villager. vm.houseTransform = trans; // Pass the shrine to the villager. vm.shrine = shrine; // Pass the food controller reference to the villager. vs.foodController = foodController; // Pass village reference to the villager. //vs.village = this; // Subscribe to the villager's events. vs.Died += VillagerStatus_Died; vs.AttackedByEnemy += VillagerStatus_AttackedByEnemy; // Pass the time controller to the villager. tc.timeController = GetComponent <TimeControllable>().timeController; TimeScale.PassTimeScale(newVillager, ts); // Add the villager to the list of existing villagers. villagers.Add(vs); } }