Пример #1
0
    // TODO: Display prompt saying player can't build
    // FixedUpdate function
    private void FixedUpdate()
    {
        if (requestToBuild)                                                         // Player requested to build
        {
            if (currentBuilding.isBuildable(spawnPoint))                            // Determine if player is able to build
            {
                if (playerResource.GetResourceCount() >= currentBuilding.buildCost) // Determine if player has enough resource
                {
                    canRequest = false;
                    audioManager.PlaySound("Deploy");
                    currentBuilding.Build(spawnPoint, grid);
                    playerResource.DisplayNumber(-currentBuilding.buildCost, Color.red);
                    playerResource.DecrementResource(currentBuilding.buildCost);
                    StartCoroutine(Wait(buildRate));
                }
                else
                {
                    Debug.Log("Not enough resource!");
                }
            }
            else
            {
                Debug.Log("Cannot build right now");
            }

            requestToBuild = false;
        }
    }
Пример #2
0
    private void OnTriggerStay2D(Collider2D other)
    {
        if (Input.GetKeyDown(KeyCode.E) && other.tag == "Build Spawn" && playerResource.ResourceCount >= worth)
        {
            if (canRepair)
            {
                playerResource.DecrementResource(worth);
                Repair();
            }
        }

        if (Input.GetKeyDown(KeyCode.E) && other.tag.Equals("Player") && playerResource.ResourceCount >= worth)
        {
            if (canRepair)
            {
                playerResource.DecrementResource(worth);
                Repair();
            }
        }
    }