Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Can you use GetMouseButtonDown, GetMouseButton, GetMouseButtonUp as 3 different actions?

Discussion in 'Scripting' started by KowlDoog, Sep 22, 2020.

  1. KowlDoog

    KowlDoog

    Joined:
    Aug 17, 2020
    Posts:
    10
    Hi guys,
    I'm testing if I'm able to get 3 actions off one input of a mouse click & hold, so far it looks like GetMouseButton overrides GetMouseButtonDown, as it doesn't print "Bunt!" ever

    Code (CSharp):
    1.     private void Update()
    2.     {      
    3.         if (Input.GetButtonDown("Fire1"))
    4.         {
    5.             Debug.Log("bunt");
    6.         }
    7.  
    8.         if (Input.GetButton("Fire1"))
    9.         {
    10.             Debug.Log("Choose action!");
    11.         }
    12.  
    13.         else if (Input.GetButtonUp("Fire1"))
    14.         {
    15.             Debug.Log("Action!");
    16.         }

    For the sake of this it'll eventually lead to an animation playing > a radial menu opening after animation > and whatever the cursor is hovering over is the action that takes place

    To me this seems like 3 separate actions but if this can be interpreted in a different way that I could look into that'd be greatly appreciated.

    Cheers
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    GetButton
    cannot override
    GetButtonDown
    ; they're two separate methods.
    What you have here should be working just fine.

    Are you sure you don't see the "bunt" message only because the console quickly gets flooded with "Choose Action!" every frame?
    Try enabling the collapse option in the console window so that duplicate messages don't get displayed, if it isn't already.
     
    Dextozz, KowlDoog and PraetorBlue like this.
  3. KowlDoog

    KowlDoog

    Joined:
    Aug 17, 2020
    Posts:
    10
    Oh I see, the collapse matches with what you said, so that's all good. So in theory what I'm tryna do with this radial menu thing should work, appreciate it!