H
H
Haddle Haddle2021-02-15 17:41:51
Unity
Haddle Haddle, 2021-02-15 17:41:51

Why is Curatin/Update checked so slowly?

I have wheat, when it is cut down, the time until it appears (2 seconds) is counted down, while there is a check that if the water is less or exactly 0, then the wheat does not grow. this.GetComponent().color = colTwo; this is me returning 100 percent transparency to wheat (I don’t destroy wheat, but make them invisible, yes, I’m down, but I need it so much now).
So, if you slowly cut down one wheat at a time, then everything works, and if there is not enough water, then the wheat does not grow. But if you cut down a lot of wheat in 1 second, then the unit does not have time to check the water, and even if it is less than necessary, the wheat still manages to return 100 percent transparency. How to fix it?

Here is my code:

using System.Collections;
using UnityEngine;

public class GotWheat : MonoBehaviour
{
  #region Variables
  public Color col;
  public Color colTwo;

  private bool isAlive = true;

  static public float timeToGrowUp = 2f;
  private int a = 0;
  static public int b = 0;
  #endregion

  #region UnityMethods
  void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Cursor" && Input.GetKey(KeyCode.Mouse0))
        {
      if (isAlive)
      {
        StartCoroutine(timeToReincornation());
        this.GetComponent<SpriteRenderer>().color = col;
        AmmountThings._Ammount++;
        isAlive = false;
      }
        }
    }
  IEnumerator timeToReincornation()
    {
        while (a==0)
        {
      if (WaterSense.currentWater > 0)
      {
        yield return new WaitForSeconds(timeToGrowUp);
        a = 1;
        isAlive = true;
        this.GetComponent<SpriteRenderer>().color = colTwo;
        WaterSense.currentWater-=0.125f;
      }
      yield return new WaitForEndOfFrame();
    }
    a = 0;
  }
  #endregion
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Haddle Haddle, 2021-02-15
@Haddle

I realized my mistake, can not help. I first checked the water and then set the rollback time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question