Esempio n. 1
0
    public IEnumerator goToBuildingCourentine(BuildingAttributes building)
    {
        if (building != null)
        {
            isMovingToBuilding = true;
            movedToBuilding    = false;
            Vector3 buildingPosition = new Vector3(building.getPositionX(), building.getPositionY(), building.getPositionZ());

            if (playerInsideBuilding == true)
            {
                leaveBuilding();
            }

            agent.SetDestination(buildingPosition);

            while (isMovingToBuilding)
            {
                if (agent.hasPath)
                {
                    if (agent.remainingDistance <= 0.6)
                    {
                        movedToBuilding = true;
                        agent.ResetPath();
                        goInsideBuilding(building);
                        break;
                    }
                }
                yield return(null);
            }
            isMovingToBuilding = false;
        }
    }
Esempio n. 2
0
    public IEnumerator goToBuilding(BuildingAttributes building)
    {
        if (building != null)
        {
            if (!isMovingToBuilding)
            {
                isMovingToBuilding = true;
                movedToBuilding    = false;

                //Debug.Log("goToBuilding har started");
                Vector3 buildingPosition = new Vector3(building.getPositionX(), building.getPositionY(), building.getPositionZ());

                if (isInsideBuilding == true)
                {
                    leaveBuilding();
                }

                citizenAgent.SetDestination(buildingPosition);

                while (isMovingToBuilding)
                {
                    if (citizenAgent.hasPath)
                    {
                        if (citizenAgent.remainingDistance <= 0.6 && !movedToBuilding)
                        {
                            movedToBuilding = true;
                            goInsideBuilding(building);
                            //Debug.Log("reached destination");
                            citizenAgent.ResetPath();
                            break;
                        }
                    }
                    yield return(null);
                }
                isMovingToBuilding = false;
            }
        }
        else
        {
            if (isInsideBuilding == true)
            {
                leaveBuilding();
            }
            if (townCurrentlyInsideOf)
            {
                citizenAgent.SetDestination(new Vector3(townCurrentlyInsideOf.getTownCenter().x + Random.Range(-8.0f, 8.0f), 0, townCurrentlyInsideOf.getTownCenter().z + Random.Range(-8.0f, 8.0f)));
            }
        }
    }