Cancelling on a Button Click

Not sure if this comes up later in the polishing section or something, but what’s a good way to cancel an ability use on a right click or similar button press? I tried putting a Cancel call in a few places but nothing seemed to work for me.

So at this point, we’ve introduced isCancelled into the UserData…

Unless there is some sort of delay, there’s not much going on to cancel, even with a keystroke, but in a script like DelayedClickTargeting.Targeting, you could do something like this in the while loop

while(!data.IsCancelled())
{
     if(input.GetKeyDown(Keycode.escape)) //spelling may be off
     {
          data.GetUser().GetComponent<ActionScheduler>().CancelCurrentAction();
          yield break;
          continue;
     }
     //Rest of the loop

You could also test for Input.GetMouseDown(1)

Is continue supposed to be inaccessible here?

if(Input.GetKeyDown(KeyCode.Escape)) //spelling may be off

                {

                    data.GetUser().GetComponent<ActionScheduler>().CancelCurrentAction();

                    yield break;

                    continue;

                }

                //Rest of the loop

While that code didn’t 100% do it, it does seem like this does, unless it’s introducing some bugs I don’t see yet:

if(Input.GetKeyDown(KeyCode.Mouse1))
      {
        data.GetUser().GetComponent<ActionScheduler>().CancelCurrentAction();
        targetingPrefabInstance.gameObject.SetActive(false);
        playerController.enabled = true;
        finished();
        yield break;
       }

Hehe, that’s what happens when I answer a question from my work computer instead of my home computer with the actual codebase and compiler in it.

That code should do it just fine.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms