How would you tie a keypress to a fill amount?
I have my health set to decrease every second by 5. I would rather be able to increase and decrease it as needed by pressing one button to replenish my health and another to subtract from it. Any suggestions?
Answer by AMU4u · Feb 24, 2017 at 07:27 PM
void FixedUpdate()
{
if( Input.GetKeyUp(KeyCode.Space)
{
currhealth -= dynamicRobustVariable;
}
if (Input.GetKey("B"))
{
currhealth += dynamicRobustVariable;
}
}
Changed it for you. Much less fancy. I would check out the input doc on unity's website for more key's to use. GetKey fires on key press, where GetKeyDown fires when the key is held down, etc.
Thank you for the script. But I didnt want the buttons on screen I was hoping to make it through keyboard input like "g" for + and "h" for - or something to that effect.
Changed it for you, just switch the keys to whatever you want to use from this list.
Thank you so much, I knew roughly what i needed just didn't know how to write it correctly. I appreciate the help for sure. :)