Hey everyone hope someone out there can help, I have a flashlight mechanic set up and it works but my problem is that the light doesn't toggle on/off with a key press (F) I have to hold F for the light to turn on and once I let go the light will turn off.
In my SleepCharacter.h
In my SleepCharacter.cpp
That is all the code relating to the Flashlight, I have been stumped for a few days now, when I hold F the flashlight will come on and when I release it will turn off. But like I said before I want it to toggle so when you press F once the flashlight will come on and the FlashlightPower will decrease, if you press F again then the light will turn off and recharge.
I hope the question is clear and the code is easy to read, I hope someone can help with this too :)
Thanks for taking a look.
asked Jun 23 '16 at 01:16 PM in C++ Programming
In your input instead of doing when you press and when you release do when you press you call a function that toggles the flashlight...
Or something close to that. That way your not looking at a release event when it doesn't matter if they release the key or not.
Your input bindings are calling this functions on the Flashlight Action Event. FlashlightOn() is called on IE_Pressed (when the key first goes down) and FlashlightOff() is called on IE_Released (when the key comes back up). Thus you're getting exactly what you're code says.
To do a toggle instead, you can remove your on/off bindings and replace them with a single binding for flashlight toggle, wherein you toggle the state of IsFlashlightOn
answered Jun 23 '16 at 01:39 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here