event trigger on 2 separate buttons
I have 2 buttons functioning separate from each other using event trigger with similar events(separate codes), but when I have one button(A) on hold and I press the other button(B) down, it cancels the function of button(A). How do I make sure their event triggers run separate from each other, especially if I need to hold both buttons down at the same time running separate functions?
Answer by lvskiprof · Mar 23, 2021 at 05:07 PM
I would think running the event being triggered as a co-routine would do what you want. That lets it run as an independent thread.
Answer by Dino999 · Mar 23, 2021 at 05:15 PM
I can give that a shot. So there's no way to have them work separately? that's annoying...
I am not sure why it is acting the way you described, as I have never run into a need to do what you are doing, but a co-routine will run separately from the main thread, which is why I suggested it.
now I'm trying to figure out these coroutine setups for button down, button hold and button up...
here's an example or what I have running for one button: and the opposite value for the other button...
the event triggers control the functions, but once the other button is pressed, it cancels this out...vice versa
public void OnMouseDown() {
ispressedB = true;
GameObject[] Flippers;
Flippers = GameObject.FindGameObjectsWithTag("Flipper");
foreach (GameObject flipper in Flippers)
{
flipper.GetComponent<Rigidbody2D>().MoveRotation(80);
}
}
public void WhileHolding()
{
if (ispressedB == true)
{
GameObject[] Flippers;
Flippers = GameObject.FindGameObjectsWithTag("Flipper");
foreach (GameObject flipper in Flippers)
{
flipper.GetComponent<Rigidbody2D>().MoveRotation(80);
}
}
}
public void OnButtonRelease()
{
ispressedB = false;
GameObject[] Flippers;
Flippers = GameObject.FindGameObjectsWithTag("Flipper");
foreach (GameObject flipper in Flippers)
{
flipper.GetComponent<Rigidbody2D>().MoveRotation(0);
}
}
Your answer
Follow this Question
Related Questions
Creating a 2D sprite with Trigger Events? 2 Answers
How do I NOT play a sound on the first selected button. 2 Answers
Selectable/Button not being selected 0 Answers
HELP ME PLEASE TO FIX MY PROBLEM.. 1 Answer