I’m currently trying to replicate flappy bird so that my bird jumps when I click on the screen.
if (Input.GetMouseButtonDown(0))
{
rb2d.velocity = Vector2.zero;
rb2d.AddForce(new Vector2(0, upforce));
}
this is the script attached to my bird but the problem is, I also have a pause button on the top right of my screen and whenever I click the pause button, the bird jumps too… is there a way of tagging the button or some function I could use so that this doesnt happen?
A pseudo code i’m after looks something like
if(input.getmousebuttondown(0) && isNotaButton) then jump.
Any help is really appreciated thanks!!
Use the UI system and make an event on an object that takes up the entire screen for your ‘jump button’ Then in front of that relative to the UI camera place your pause button. The pause button will intercept the input and it’ll not click the ‘jump button’ behind it.
Ok that sounds like the things I’m after. I’ve only been into unity for around 2 weeks… Could you please explain how I would create such event on an object ?
Yes I’ve had a look at all those and made it work by using a different method using
public void Update() {
if(!EventSystem.current.IsPointerOverGameObject())
{
if (Input.GetMouseButtonDown(0))
{
rb.velocity = new Vector2(rb.velocity.x, jump);
}
}
}
.
The above script is attached to my player.
I’m still wondering though how I would carry out the method you mentioned? I tried moving the pause button in the z axis so that it lies infront of the panel but again the “Input.GetMouseButtonDown(0)” seems to ignore the fact that the button is infront and still jump when i click the pause button.
You mention moving “relative” to UI camera. Is that different to just moving it in the z axis?
Also you mention adding event to gameobject so that it uses entire screen to jump. Isnt this what the Input.GetMouseButtonDown(0) function does?