private void Update()
    {
        if (target == null)
        {
            return;
        }

        if (target.plantComponent == null)
        {
            harvestTime.text           = "No plant!";
            harvestButton.interactable = false;
            plantButtons.SetActive(true);
            currentPlantInfoBox.SetActive(false);
            return;
        }

        if (!target.CheckRipe())
        {
            float timeLeft = target.timeTillRipe - Time.time;

            harvestTime.text           = string.Format("{0:00}", timeLeft);
            harvestCooldown.fillAmount = timeLeft / target.plantComponent.harvestTime;
            harvestButton.interactable = false;
        }
        else
        {
            harvestCooldown.fillAmount = 0;
            harvestTime.text           = "Ready!";
            harvestButton.interactable = true;
        }
    }
示例#2
0
    public void Harvest(bool calledFromClient = false)
    {
        if (destroyed)
        {
            return;             //can be called twice if both players try to take the same thing
        }
        if (calledFromClient)   //if the other player took this resource, destroy it and dont award resources to this player
        {
            Destroy(Instantiate(hitEffect, transform.position, Quaternion.identity), 2f);
            destroyed = true;
            Destroy(gameObject);
            return;
        }

        if (!node.CheckRipe())
        {
            Destroy(Instantiate(onCooldownHitEffect, transform.position, Quaternion.identity), 2f);
        }
        else
        {
            Destroy(Instantiate(hitEffect, transform.position, Quaternion.identity), 2f);
            CheckResources();

            WaveSpawner.Instance.commands.CmdHarvest(node.nodeID);

            Destroy(gameObject);
        }
    }
    public void SetTarget(GardenNode _target)
    {
        if (!WaveSpawner.Instance.gameStarted)
        {
            BuildManager.Instance.message.PlayMessage("Cannot plant until game starts!", _target.transform, Color.white);
            return;
        }
        if (_target == target)
        {
            Hide();
            return;
        }

        target = _target;

        transform.position = target.transform.position;

        if (target.plantComponent != null)
        {
            plantButtons.SetActive(false);

            currentPlantInfoBox.SetActive(true);
            currentPlantNameText.text      = target.plantComponent.displayName;
            currentPlantInfoText.text      = target.plantComponent.info;
            currentPlantInfoBoxImage.color = target.plantComponent.displayColor;
        }
        else
        {
            plantButtons.SetActive(true);
            currentPlantInfoBox.SetActive(false);
            harvestCooldown.fillAmount = 0;
        }

        if (!target.CheckRipe())
        {
            harvestTime.text           = target.timeTillRipe - Time.time + " seconds till ripe!";
            harvestButton.interactable = false;
        }
        else
        {
            harvestTime.text           = "Ready!";
            harvestButton.interactable = true;
        }
        UI.SetActive(true);
    }