/* This is the method which checks whether or not an agent has arrived its destination. This method is called * in every frame. */ void CheckArrived() { if (status == all_states.atHome || status == all_states.atWorkPlace) { return; } if (transform.position.x >= dest_x - 1.5 && transform.position.x <= dest_x + 1.5 && transform.position.z >= dest_z - 1.5 && transform.position.z <= dest_z + 1.5) { if (dest_x == workplace_x) { status = all_states.atWorkPlace; transform.position = new Vector3(workPlace.transform.position.x, transform.position.y, workPlace.transform.position.z); } else if (dest_x == house_x) { status = all_states.atHome; transform.position = new Vector3(house.transform.position.x, transform.position.y, house.transform.position.z); } else { status = all_states.atHospital; float spawnX = Random.Range(-20, 20); float spawnZ = Random.Range(-20, 20); transform.position = new Vector3(healthScript.hospitalToGo.transform.position.x + spawnX, transform.position.y, healthScript.hospitalToGo.transform.position.z + spawnZ); healthScript.SetDetected(); } } }
/* This is method to change the agent's status from atHome to onRoad. Called by the agent's house object. * Param: * road -- the first road that the agent will travel on * startPos -- the position at the first road that the agent will start at. */ public void SetOnRoad(GameObject road, float start_x_p, float start_z_p, float dest_x_p, float dest_z_p) { start_x = start_x_p; start_z = start_z_p; dest_x = dest_x_p; dest_z = dest_z_p; Vector3 startPos = new Vector3(start_x, transform.position.y, start_z); transform.position = startPos; curRoad = road; status = all_states.onRoad; onFirstRoad = true; distTravelled = 0; }