// Start is called before the first frame update
    void Start()
    {
        GameObject villageCenter = GameObject.FindWithTag("VillageCenter");

        resourceTracker = villageCenter.GetComponent <TrackStorageResources>();
        InvokeRepeating("GenerateFarmFood", 5.0f, foodSpawnRate);
    }
예제 #2
0
    void Update()
    {
        // check if user created village center yet
        if (resourceCounterScript == null)
        {
            if (GameObject.Find("VillageCenter(Clone)") != null)
            {
                resourceCounterScript = GameObject.Find("VillageCenter(Clone)").GetComponent <TrackStorageResources>();
            }
        }

        if (draggingNewBuilding)
        {
            float posX = Input.mousePosition.x;
            float posY = Input.mousePosition.y;
            // 10 units below the camera, so that the player can see where the building is
            if (camera.transform.position.y > 8.99)
            {
                if (buildingToDrag == null)
                {
                    return;
                }
                buildingToDrag.transform.position = camera.ScreenToWorldPoint(new Vector3(posX, posY, 9));
            }
            else
            {
                // nearer the camera so that the building doesn't go under the map
                buildingToDrag.transform.position = camera.ScreenToWorldPoint(new Vector3(posX, posY, camera.transform.position.y * 0.8f));
            }
            DragBuilding(buildingToDrag);
        }
        else
        {
            // player can place a building only if mouse has been moved away from the creation position
            // because the creation position is usually the UI position
            if (Vector3.Distance(creationPosition, Input.mousePosition) > 7)
            {
                if (buildingToDrag != null)
                {
                    PlaceBuildingOnFreePlainsTile();
                }
                else
                {
                    StopDraggingBuidling();
                }
            }
            else
            {
                draggingNewBuilding = true;
            }
        }
    }