How do I properly do a 2D raycast to avoid problem with pause button?
So I have an android game where a character jumps when the screen is tapped. The only problem is that whenever the pause button is tapped a "jump" goes through as well. So to fix that I am trying to send a 2D raycast to the screen on every tap so that the jump function will only be called if nothing is hit. Here is my update function:
private void Update()
{
if (game.IsGameOver) return;
if (Input.GetMouseButtonDown(0) && !game.GamePaused)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.forward, 1, mask.value);
if (hit.transform == null)
{
Jump();
}
}
}
However my fix appears to do nothing at all. Also, "mask" is a public layerMask that is assigned to the layer the pause button is on. The pause button is also the only gameobject on that layer. Are my parameters wrong for the 2D raycast? I've looked around online and am only seeing solutions for 3d raycasting. Is that what I should be using even though my game is 2d? Sorry if this questions has already been answered. Thanks for any help.