IPointerClickHandler and DelayedClickTargeting

Hi

Im getting a small bug , if you implement the way you use abilities with mouse click on the on the action buttons
instead of pressing the keyboard for use abilities then the cursor doesnt change until you click again
if that makes sense to anyone

like the cursor change then you need to click 2 times

but if do with the keyboard the ability need to only click once

About the Strategy Pattern , this is interesting stuff and how to use it .
last time i used this pattern was in university i think .

I think need a little bit more explaining for the why we using

Action <IEnumearble<GameObject>>

For me i understand where you going with this
you want to have call backs for actions probably later to make like some action priority

But i think need more explaining for this for other students

I’m not sure I understand. What are the reproduction conditions?

In my version of the game

on ActionSlotUI i have this , and i implement an Interface Called IPointerClickHandler

public void OnPointerClick(PointerEventData eventData)
        {
            var player = GameObject.FindWithTag("Player");
            store.Use(index, player);
        }

Then when i press the action it will use the action
what happens is when we do the change for cursor in DelayedClickTargeting
it keeps the cursor in the same change state
if i do it with the keyboard in Update like you did in the PlayerController script
for using abilities it doesnt do that

I mean it will go back to the movement cursor or shop cursor or other cursors but after you click

Not sure what’s going on there. Do you have any difference in how the coroutine is implemented? Can you share that code.

Its the same as done in the videos

private IEnumerator Targeting(GameObject user, PlayerController playerController, Action<IEnumerable<GameObject>> finished)
        {
            playerController.enabled = false;
            while (true)
            {
                Cursor.SetCursor(cursorTexture, cursorHotspot, CursorMode.Auto);

                if (Input.GetMouseButtonDown(0))
                {
                    // Absorb the whole mouse click
                    yield return new WaitWhile(() => Input.GetMouseButton(0));
                    playerController.enabled = true;
                    finished(GetGameObjectsInRadius());
                    yield break;
                }
                yield return null;
            }
        }

I Found the problem it is the Input.GetMouseButton need to change to Input.GetMouseButtonDown

Oh but now if i do it with Keyboard it walk over there
With the mouse its fine now , with the keyboard if press the abilitiy and press the mouse to release it will walk

So if changing to

yield return new WaitWhile(() => Input.GetMouseButtonDown(0));

with mouse it work fine with keyboard click on 1 - 6 for choose the ability it makes the player move
its like skipping it

While I cannot explain why this is happening, I can confirm on my end (I believe I actually gave @babi6k the code to click the buttons) that this is happening. It seems illogical since the anomoly only happens if you begin the Use() from the IPointerClickHandler, not when you call it using the Keycode.Alpha0.

The downside of this current patch is that the targeting (and hence the action) will happen immediately upon clicking, but the cursor does return to normal after releasing the mouse button (and again, since WaitWhile(()=>Input.GetMouseButtonDown(0)); is functionally equivalent to yield return new WaitTilEndOfFrame() (Input.GetMouseButtonDown(0) is only valid for exactly one frame) I can’t actually explain why the cursor holds on until the mouse button is released either.

I wonder why it’s happening
For now i fixed it only for mouse but i think should have option for use keyboard or mouse
Maybe have something different then IPointerhandler

I actually ran back over the logic here… WaitWhile(()=>Input.GetMousebuttonDown(0)); in this context is functionally equivalent to yield return null; or yield return new WaitTillEndOfFrame();. GetMouseButtonDown(0) is only true within the frame that it is clicked.

I still haven’t figured out the root cause of this. It shouldn’t matter what the source of the call to Use() is. All the button is doing is exactly what the PlayerController is doing, calling store.Use(index, player).

The AIController is disabled in both cases, and then reenabled at the end (at which point the cursor should be set in AIController’s Update method) This bug is still low on my priority list for the time being, I have a couple of bigger issues to work on, but it is on my TODO (my own game also allows you to click the ActionSlot to launch the ability.).

1 Like

Privacy & Terms