Right-click button using GUI class?

Hey, I am trying to use the standard GUI class to implement buttons... As far as just clicking them, everything was pretty easy:

function OnGUI {
   var myButton = GUI.Button(Rect(), myString)

   if(myButton) {
      //Do something crazy
   }
}

However, if I want something different to happen when the user right-clicks the button, how could that be done? I'm thinking something like:

function OnGUI {
   var myButton = GUI.Button(Rect(), myString)

   if(myButton) {
      if(mouseButton1) {
         //Action 1
      } else {
         //Action 2
      }
   }
}

Does that make sense? If it does, how do I implement it "correctly"?

You'll want to look at the current GUI event to see which button was pressed. Try this code:


    if (GUILayout.Button("MyButton")
    {
        if (Event.current.button == 0)
            Debug.Log ("MyButton was clicked with left mouse button.");
        else if (Event.current.button == 1)
            Debug.Log ("MyButton was clicked with right mouse button.");
    }

Maybe sth like that?

private var actives = false;
private var actives2= false;

function OnMouseDown  () {
     if(Input.GetMouseButton(1)){
     actives = actives ? false : true;
     }
     if(Input.GetMouseButton(0)){
     actives2= actives2 ? false : true;
}
}

function OnGUI () {
     if (actives) {
          GUI.Label (Rect (50,50,100,50), "test");
      }
     if (actives2) {
          GUI.Label (Rect (50,50,100,50), "test");
      }
} 

actives = actives ? false : true;

means

actives = !actives;