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

Which mousebutton is held down/pressed?

Discussion in 'Scripting' started by gorbit99, Apr 22, 2016.

  1. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Is there any better way of checking which mouseButton is pressed other than:
    Code (CSharp):
    1. if (Input.GetMouseButtonDown(0))
    2.    held = 0;
    3. else if (Input.GetMouseButtonDown(1))
    4.    held = 1;
    5. ...
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Input.GetMouseButton
     
  3. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    It doesn't return the actual id of the mouseButton
     
  4. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Sorry i read your question wrong.
    I guess you could go for a for loop
    Code (CSharp):
    1. for(int i = 0; i < *number of mouse buttons*; i++){
    2.     if(Input.GetMouseButtonDown(i)){
    3.         held = i;
    4.     }
    5. }
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,181
    What do you want to happen if both mouse buttons are held down?
     
  6. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Well, if it's possible to get an array/list of these, that would be perfect, but I would prioratize the one with smaller id