- Home /
Input in OnTriggerStay2D
private void OnTriggerStay2D(Collider2D collision)
{
Player ply = collision.GetComponentInParent<Player>();
if (!ply.dead)
{
if (gm.inputs[ply.player].B && !gm.prevInputs[ply.player].B && !ply.itemEquiped && ply.takeCooldown <= 0)
{
//stuff
}
}
}
}
I'm making a 2D game in which there's items you can pickup when pressing B
Everything works fine in the editor but doesn't on the build, because OnTriggerStay2D only runs when FixedUpdate does so the Inputs get broken..
Any workaround ?
Answer by bpaynom · Mar 06, 2019 at 01:06 PM
Use a flag, update it on trigger enter / stay / exit as you need it, then make the input in Update() callback checking that flag and other conditions.
Can't do that because it's a 4 player game so there could be 2-3 players at the same time on the item
I fixed it just by removing the "!gm.prevInputs[ply.player].B" and checking that the player releases the B button before being able to drop it by pressing B again
Your answer
Follow this Question
Related Questions
Trigger in child - boxcollider2d without trigger on parent issues. 0 Answers
How to Handle Corners on a Slope in a 2D Platformer Game? 0 Answers
How do I do a Snappy Jump in 2D with a 2D Jump Script? 0 Answers
How to have the character fall when disabling collisions with layer its currently on? 1 Answer