I have code that while a button is pressed, strength goes up and when it is released, it launches missile at the strength.
Sometimes, even while i am pressing the button, it thinks i released and launches missile.
I think sometimes Update() doesn't think the key is pressed?
Here is my code
bool pressed;
void OnPress(bool pressed)
{
this.pressed = pressed;
}
public const float PowerMultiplier = 15.0f;
bool previouslyPressed;
void Update()
{
if(LaunchMode)
{
if(pressed)
{
if(!previouslyPressed)
{
Messenger.Broadcast("PLAYERTANK_RESET_POWER");
previouslyPressed = true;
}
Messenger.Broadcast("PLAYERTANK_UPDATE_POWER");
}
else if(previouslyPressed)
{
previouslyPressed = false;
LaunchMode = false;
Messenger.Broadcast("PLAYERTANK_LAUNCHED");
}
}
else
{
//todo: shield mode
}