Hello,
Im working on my 2d game, and I’m trying to make a mobile button which will be responsible for shooting projectiles. I found an event trigger system, and i have a problem with this, because im using Pointer Down, Pointer Click, and Pointer Up.
Pointer Down and Pointer Up are working perfectly, but Pointer Click does not increase value of my variable “in real time?”, no matter how long i’m holding button he always add same value to my variable.
I’m kinda stuck on this task (making this button) for a while, can i get any hint from you?
I think you might be going down a more complicated route with the pointer handler stuff. You can use unity’s own button component to do this:
Right click in the hierarchy window, find UI then in that sub-menu find Button and select that. In your script that handles the firing of projectiles, create a serialized field reference to that button. Then finally in your awake / destroy function you can assign and un-assign the button listener.
Here is an example:
public class KoopixdsProjectileFirer : MonoBehaviour
{
// This is your reference to the fire button, drag this in in the inspector
[SerializeField] private Button _fireButton;
private void Awake()
{
// when the player clicks the fire button, call the FireButtonListener function
_fireButton.onClick.AddListener(FireButtonListener);
}
private void OnDestroy()
{
// when this object gets destroyed, remove the listener we added
_fireButton.onClick.RemoveListener(FireButtonListener);
}
private void FireButtonListener()
{
Debug.Log("Fire!");
// Here you can add in your current fire-projectile code
}
}
Let me know if this isn’t applicable to your situation or if I misunderstood the question. Hope this helps!
Hello,
Thanks for the answer, and sorry if my question was not clear 
I have my little platformer 2d game, and i want to add a mobile button for shooting in it, which will recognize three states:
-when button is pressed
-when button is helding down
-when button is released
And when i’m trying different solutions always this second state (when button is helding down) is not working 