private void Build(GameObject agentGO) { AgentActionsSelector agent = agentGO.GetComponent("AgentActionsSelector") as AgentActionsSelector; if (agent.CanBuildBridge() && (stage < (rocksNeeded))) { transform.GetChild(stage).gameObject.SetActive(true); stage = stage + 1; if (stage >= rocksNeeded) { stage = rocksNeeded - 1; } } if (stage == (rocksNeeded - 1)) { gameObject.tag = "BridgeAvailable"; UnityEngine.AI.NavMeshObstacle navOb = gameObject.GetComponent(typeof(UnityEngine.AI.NavMeshObstacle)) as UnityEngine.AI.NavMeshObstacle; if (navOb != null) { navOb.enabled = false; } } }
private void Build(GameObject agentGO) { AgentActionsSelector agent = agentGO.GetComponent("AgentActionsSelector") as AgentActionsSelector; if (agent.CanBuildHouse() && (stage < (rocksNeeded))) { transform.GetChild(stage).gameObject.SetActive(true); stage = stage + 1; if (stage >= rocksNeeded) { stage = rocksNeeded - 1; } } if (stage == (rocksNeeded - 1)) { if (agentsAllocatedToHouse == MAX_AGENTS) { gameObject.tag = "HouseBuiltFull"; } else { gameObject.tag = "HouseBuiltAvailable"; } } }
private void AlertActionSelection() { for (int i = 0; i < transform.childCount; i++) { AgentActionsSelector agent = transform.GetChild(i).GetComponent("AgentActionsSelector") as AgentActionsSelector; agent.ForceWorkChange(); } }
void Update() { if (isPlaying) { if (Time.time >= nextNight && !isNight) // Time to pick a new work { nextDay = Mathf.FloorToInt(nightLength) + Mathf.FloorToInt(Time.time); isNight = true; nightObject.SetActive(true); for (int i = 0; i < transform.childCount; i++) { AgentActionsSelector agent = transform.GetChild(i).GetComponent("AgentActionsSelector") as AgentActionsSelector; agent.IsNight(); } predatorsManager.GetComponent <PredatorsManager>().setNight(true); } if (Time.time >= nextDay && isNight) // Time to pick a new work { nextNight = Mathf.FloorToInt(dayLength) + Mathf.FloorToInt(Time.time); isNight = false; nightObject.SetActive(false); for (int i = 0; i < transform.childCount; i++) { AgentActionsSelector agent = transform.GetChild(i).GetComponent("AgentActionsSelector") as AgentActionsSelector; agent.IsDay(); } daysPassed = daysPassed + 1; daysUntilNextMigrant += 1; predatorsManager.GetComponent <PredatorsManager>().setNight(false); UpdateAverages(); } if (daysUntilNextMigrant >= 10) { if (isImmigrationOn) { Debug.Log("immigration"); (gameObject.GetComponent("AgentsCreator") as AgentsCreator).MigratePopulation(50); } daysUntilNextMigrant = 0; } } }
private IEnumerator KillAgents() { yield return(new WaitForSeconds(75f)); AgentActionsSelector[] agents = agentManager.transform.GetComponentsInChildren <AgentActionsSelector>(); int killOrNot = Random.Range(0, 100); if (isNight) { if (agents.Length > 0) { for (int i = 0; i < agents.Length; i++) // for (int i = 0; i < agents.Length/10; i++) { if (killOrNot < NIGHT_KILL_PERCENTAGE) { AgentActionsSelector agent = agents[i].GetComponent("AgentActionsSelector") as AgentActionsSelector; agent.GotEaten(); } } } } }