Quantcast
Channel: Questions in topic: "invokerepeating"
Viewing all articles
Browse latest Browse all 220

InvokeRepeating help

$
0
0
Hey everyone, i have a problem with InvokeRepeating and variables. I have a float called hunger, and im using an InvokeRepeating to make sure the hunger float decreases every x seconds. This works fine, but what i want is for it to decrease even faster if i hold down a button. Therefor, i obviously use variables, which you can see in my code below. When i press said button, i can see the variables change in the inspector, but the hunger float is actually not decreasing any faster. Is this some sort of limitation w/ InvokeRepeating? Or is something wrong with my code? C#: public TextMeshProUGUI hungerText; public float hunger; public float hungerDelay; public float hungerRate; // Use this for initialization void Start () { //hungerDelay = 0.5f; hunger = 100; InvokeRepeating ("HungerDecay", hungerDelay, hungerRate); } void Update () { hungerText.text = "" + hunger; //hungerSpeed -= 0.1f; if (Input.GetKey (KeyCode.LeftShift)) { hungerRate = 0.0001f; } void HungerDecay() { hunger -= 1; } }

Viewing all articles
Browse latest Browse all 220


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>